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 :)

Super useful, just a couple days too late for me… (Stupid me, built a shell script to do the same thing cause there’s NO documentation out there on the bake script.)
@Dave: Oh, that’s bad luck… I hope it wasn’t just a waste of time and you learned something by writing your shell script.
At least I can do more with the command line now. But yes, BAD luck indeed.
[...] cakebaker » Baking views Explains how to override the default scaffold code with your own (tags: cakephp bake scaffold) [...]
Hi cakebaker.
Firstly, thanks for putting together and maintaining such a useful cake resources :-)
Secondly, your example shows how to bake views from templates. Is there any way to build controllers from templates too?
I had a dig around in cake\console\libs\templates but couldn’t spot any templates for controllers.
@Richard: Thanks for your comment!
No, there are no templates for controllers, see cake/console/libs/tasks/controller.php
Thanks for confirming it. I did go and dig around further in the source and while doing so realised it is not something that would lend itself easily to templating.
@Richard: Yes, that’s true, even though it would help to avoid hard-coding the entire template in the task.