06-12-2012, 06:05 PM
Code Generation with Bake
Code Generation.docx (Size: 86.78 KB / Downloads: 34)
CakePHP’s Bake console is another effort to get you up and running in CakePHP – fast. The Bake console can create any of CakePHP’s basic ingredients: models, views and controllers. And we aren’t just talking skeleton classes: Bake can create a fully functional application in just a few minutes. In fact, Bake is a natural step to take once an application has been scaffolded.
Those new to Bake (especially Windows users) may find the Bake screencast helpful in setting things up before continuing.
Depending on the configuration of your setup, you may have to set execute rights on the cake bash script or call it using ./cake bake. The cake console is run using the PHP CLI (command line interface). If you have problems running the script, ensure that you have the PHP CLI installed and that it has the proper modules enabled (eg: MySQL).
When running Bake for the first time, you’ll be prompted to create a Database Configuration file, if you haven’t created one already.
View Templates
The view layer of CakePHP is how you speak to your users. Most of the time your views will be showing (X)HTML documents to browsers, but you might also need to serve AMF data to a Flash object, reply to a remote application via SOAP, or output a CSV file for a user.
By default CakePHP view files are written in plain PHP and have a default extension of .ctp (CakePHP Template). These files contain all the presentational logic needed to get the data it received from the controller in a format that is ready for the audience you’re serving to. If you’d prefer using a templating language like Twig, or Smarty, a subclass of View will bridge your templating language and CakePHP
View files are stored in /app/View/, in a folder named after the controller that uses the files, and named after the action it corresponds to. For example, the view file for the Products controller’s “view()” action, would normally be found in /app/View/Products/view.ctp.
The view layer in CakePHP can be made up of a number of different parts. Each part has different uses, and will be covered in this chapter: