Generate Full Working CRUD Skeleton Using CakePHP 2.x Bake Console

How To Generate A Full Working CRUD Skeleton Using CakePHP 2.x Bake Console?
Social sharing

CakePHP’s bake console is a command line tool to build fully functional CRUD(Create, Read, Update, Delete) skeleton for your project. As we know CakePHP 3.x is at our doorstep and scaffolding has been removed from it. Cake’s bake console is the extensive scaffolding that generates well documented code for the CRUD operation.

The Cake’s bake console helps you to generate the code for model validations and model relationship. It will ask you, what kind of validation you want and also suggest you the model relationship as per the database convention. We just have to confirm them in command prompt. Going further, Bake can also write Unit Tests for you.




  1. Set the environment variable in your windows machine. Add this line on your environment path –“;D:\xampp\php\;D:\xampp\htdocs\myproject\app\Console\;”
  2. Open the windows command prompt and go to the path – myproject/app/Console

NOTE: If you you have git bash in windows, you don’t have to set the environment variables. Go to the project folder myproject/app/Console and open git bash.


  • No configurations needed, just go to the path – myproject/app/Console in your command line.



The bake console commands are very easy. It is well documented and it will walk you through the process while you are generating the code.

cake bake   is the command to start generating CRUD and it will ask, what do you want to bake.

cake bake all – this will generate code for your model, view and controller. But before that, it will ask you to select a model(as per the database table).

Other commands are: cake bake controller, cake bake model, cake bake view, cake bake project

List of Files (Command: cake bake all)

  • It creates your Controller with four actions – index, view, add, edit.
  • The same index, view, add, edit .ctp view files will be created respectively in the view folder.
  • Model file will be created with all the validations and relationships stated by you while generating them on bake console. (If you have an existing Model, it will ask you to overwrite that)



  • In the add.ctp file you can find the form and the fields to add a new record.


  • The listing(index.ctp) comes with sorting and pagination.
    The view.ctp is the view details of the record.


  • It is the edit.ctp, file with pre-filled data in the form to edit the record.


  • In the listing, you can find the delete link in each records to delete that record.

People say, Cake’s bake is the best friend of “lazy type” developer, but its not true. Smart developer does things quicker and faster with the help of CakePHP’s bake console.

We hope this article would help you to kickstart your CakePHP project real quick. If you have any question or suggestions, you can ask us in the comment section.

Your recently viewed posts:

Jayadev Das - Post Author

Do what you do best in – that’s what I’ve always believed in and that’s what I preach. Over the past 25+ years (yup that’s my expertise ‘n’ experience in the Information Technology domain), I’ve been consulting to small, medium and large companies ‘About Web Technologies, Mobile Future as well as on the good-and-bad of tech. Blogger, International Business Advisor, Web Technology Expert, Sales Guru, Startup Mentor, Insurance Sales Portal Expert & a Tennis Player. And top of all – a complete family man!

    Contact Us

    We’d love to help & work with you

    When do you want to start ?

    Enter your email address to stay up to date with the latest news.
    Holler Box

    Orange Exit pop up

    Subscribe for the latest
    trends in web and
    mobile app development
    Holler Box

    Exit pop up

    Sad to see you leaving early...

    From "Aha" to "Oh shit" we are sharing everything on our journey.
    Enter your email address to stay up to date with the latest news.
    Holler Box