Baking views

Published on and tagged with bake  cakephp  view

In Faster baking of controllers with the bake shell script I showed you some shortcuts for baking controllers. In this article I am going to show you shortcuts for baking views.

Similar to baking a controller you can now specify the controller for which you want to bake views:

cake bake view Users

This will generate views for all actions in the specified controller (for delete() actions no view is generated).

If you want to bake only a single view, you can specify which view to bake with:

cake bake view Users index

This will generate the index view for the UsersController.

In both cases, bake uses the templates in /cake/console/libs/templates/views to generate the views. You can now override those templates or even define your own templates by creating view files in /app/vendors/shells/templates/views or in /vendors/shells/templates/views. For example, if you want to create a template for “info” views, you would have to create the file “info.ctp” in one of the aforementioned folders.

The statement to generate a view by using a certain template is imho a bit illogical:

cake bake view Users info index

This statement creates the “index” view by using the “info” template. I think it would be more logical if it would be the other way around…

Anyway, happy baking :)

© daniel hofstetter. Licensed under a Creative Commons License