15 Minutes with CakePHP

I recently gave a quick, and I mean quick, presentation on CakePHP to our San Diego PHP User Group. The presentation consisted of 5 slides of which only 2 were actually about CakePHP. The rest of my presentation was me building a quick blog which I might add I successfully did in about 15 minutes.

SDPHP CakePHP Presentation 1 SDPHP CakePHP Presentation

So the presentation went something like this:

But it probably goes without saying that 2 slides and a quick 15 minute demo really doesn't do a framework like CakePHP justice. CakePHP is an awesome framework with a ton features and of course you can always read the documentation yourself. However, there did seem to be a lot of interest in the command line interface I was using to build my demo code with.

I showed a lot of the functionality of the 'Console/cake bake' command. To recap a little.

> Console/cake bake
---------------------------------------------------------------
App : app
Path: /path-to/project/app
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
>

I also demonstrated you can run

> Console/cake bake all

and we saw all sorts of auto code generation magic happen.

But there are also other options I didn't touch one.

> Console/cake bake db_config
> Console/cake bake model
> Console/cake bake view
> Console/cake bake controller
> Console/cake bake project
> Console/cake bake fixture
> Console/cake bake test
> Console/cake bake plugin plugin_name

One of my complaints was that CakePHP didn't have built-in migrations. Cake does have a couple commands to make moving database around a little easier.

Now we take a look at Console/cake schema.

We start with

> Console/cake schema generate

This will generate a schema.php of the data in your projects database.

To then use this data on another project or database you run

> Console/cake create create

which uses that schema.php to import the schema.

You can also use the schema command to create a database dump file

> Console/cake schema dump --write filename.sql

Cake Shell also comes with a ACL Shell interface for managing and inspecting Acl databases. We spoke a lot about the need to run PHPUnit test and touched on how cake bake had the option to generate test files. As such the command line interface also includes

> Console/cake test

One of the more interesting commands, and one I have not tried using myself is the Upgrade command.

> Console/cake upgrade all

According to the Cake documentation "The upgrade shell will do most of the work to upgrade your CakePHP application from 1.3 to 2.0." which, if worked as advertised, would make updating projects to the latest version of the framework a lot easier.

The full list of shells available look like this

Available Shells:

[CORE] acl, api, bake, command_list, console, i18n, schema, test, testsuite, upgrade

Hope this perks the interest of some of you to give CakePHP a try.