Getting started with bin/cake bake in CakePHP

Written by Deep

To reduce your consuming time in writing code, CakePHP provides its in-built PHP-CLI named as bin/cake . You need to just install this through composer and setting it’s PATH depending on your system. Then you can enjoy the magic of it.
Before using this make sure you have a working connection with DB.

To check if it has been properly installed try the following command from your application’s root directory using Terminal or Command Prompt:

This will show you the list of all available features. I am going with CakePHP 3.* version.

  • Controllers
    To generate controller files use the following command:
    This will generate UsersController file in /your_web_root/src/controller/UsersController.php . The above command will also generate Test Controller. If you don’t want to generate Controllers for use --no-test  as :
  • Plugins
    To create your own plugin with CakePHP use
    And generating Controllers for your CakePHP Plugin use :
  • Templates
    If you want to generate basic CURD oepertaion views for your predefined Database tables / model in CakePHP use following command  :
    For generating view/ templates for  perticular Model use:
    Here <modelName> is your model and action is name of your method. It may be having values like : create, update, listAll etc.

    I am also exploring the rest of the commands as I am new to CakePHP, and will add here in future. Please suggest if you have more. Stay Tuned!

Leave a Comment