Baking a bit faster with the bake script

Published on and tagged with bake  cakephp

With the new console infrastructure in CakePHP 1.2 the way bake is used changed a bit. You now call it with:

cake bake

When using this command you will get this dialog:

What would you like to Bake? (M/V/C)

If you know what to bake, this dialog is rather bothering. Fortunately, it is now possible to skip this dialog by providing the type of what you want to bake directly on the command line:

cake bake controller  // for baking a controller
cake bake model  // for baking a model
cake bake view  // for baking views     

Even with this shortcut there are still many questions you have to answer during the baking process…

13 comments baked

  • Tom

    nice but….i guess the direct way is the longer one ;)

  • Brandon

    You can extend the bake functionality by including var $tasks = array(‘Controller’, ‘Model’); in your Task and then call $this->Model->__bake(..); and $this->Controller->__bake(..) within your task.

    I did this to make a neat little “scaffold” task that assumes associations with the model and automatically bakes both Model and Controller (plus has support for plugins1).

    cake scaffold Articles plugin=admin


  • spark


    a solution to this would be the script reading a queue of answers, since they are almost the same… and only ask something in case of error..
    something like:
    cake bake (controller|1|y|n|n|n|y)
    cake bake (controller|2|y|n|n|n|y)
    cake bake (controller|3|y|n|n|n|y)

    Another solution would a command to generate Models, for instance, to ALL tables , following the same answers.

    But always remember the time saver it already is :)

  • Samuel DeVore

    I just wish I could just continue with the next model/controller/view after I finish so i don’t have to make my lazy old self restart every time… and that it remembered what I had already done…

  • gwoo

    There are some good ideas here. It would be nice to have some of them submitted as enhancements. The plan is to extend the tasks to do something similar to what Brandon is proposing. Also, I guess I need to change the bake methods in each of the tasks to be public.

  • cakebaker

    @all: Thanks for your comments!

    @spark: Yes, I agree that it would be cool to have the possibility to specify all options as command line parameters. But I think it should look different than your proposal ;-)

    @Samuel DeVore: Yes, that are some good points.

  • cakebaker » Faster baking of controllers with the bake shell script

    […] a previous post I wrote about a shortcut to make the baking a bit faster. In the meantime new shortcuts have been […]

  • CakePHP 1.2: The Romance Continues … « Ahsan’s Laboratory

    […] Baking a bit faster with the bake script by […]

  • Lo nuevo en CakePHP 1.2 y las diferencias con CakePHP 1.1

    […] Baking más rápido con el script bake por Cakebaker […]

  • Xander

    Another solution would be to create self-running batch file like

    cake bake model

    But the questions will still be in the air…

  • cakebaker

    @Xander: In the meantime there is a faster way to bake models, see Faster baking with bake.

  • April Silver

    There’s something missing … because when I try the nice and simple cake bake, I get bash errors.

    kiwi april$ cake bake
    -bash: cake: command not found

  • cakebaker

    @April: Well, you have to add the cake/console directory to your path. Alternatively, you have to call the script with specifying the path, like $ /path/to/cake/console/cake bake

    Hope that helps!

© daniel hofstetter. Licensed under a Creative Commons License