Archive

Posts Tagged ‘Baking’

cakePHP: Baking the Models

November 13th, 2008

After you have created your tables in your database you are ready to start Baking!

Bake is a command line tool that can be executed as a script. Open up terminal (Mac OS X) and go to your cake/console directory. From there you can start the command line tool for baking with

./cake bake

This works similiar if you are running Windows - for details on this check the docs. So after the script has launched you will see a screen similiar to this one:

Using Command Tool to Bake the Models

Choose M and the Baking for the models begins. You a first asked what kind of database configuration you would like to use. Just hit enter to use the default one. Then you can select what model you would like to bake. The list of possible models corresponds to the tables that you have created in the database:

Baking the models

After you have chosen the first table a series of questions will be asked. I would recommend not to use validation at this point as it can be done afterwards quite easy. But you should definitely bake the associations. Specific questions will be answered on your database model and you should select the right data associations (prerry straight forward):

Baking the models

After everything has been defined and looks good the model will be baked. You have to repeat those steps for every table that you want to access through a data model (most likely all of them). When you are done have a look at your app/models folder - in there you will find a PHP file for each model you have baked! Beautiful, isn’t it! The next step would be to bake the controllers.

cakePHP , , ,