Generate code with CakePHP’s cake bake command

Overview

In this tutorial I’ll show you in 25 minutes how to generate some basic CRUD functionality into your CakePHP website without writing a single line of code! This can be done by using the console which you get for free with CakePHP.
This is a great way to get up’n’running in minutes and start from what CakePHP has generated for you.

In this tutorial I’ll be covering

  1. Downloading CakePHP
  2. Creating database tables
  3. Generate Models based on database tables, controllers and views
  4. Setup the $PATH environment variable so you can call the cake command from everywhere on your system

Possible issue

If you get the following error while trying to bake your models

PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/Frederik/PROJECTS/tutorials/php/cakeBake/lib/Cake/Model/Datasource/Database/Mysql.php, line 149
PHP

you have to symlink your mysql socket file in Terminal. Do the following in Terminal:

cd ~ // go to home directory
sudo mkdir /var/mysql // create a directory in var/mysql,
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock // create a symbolic link between your mysql.sock file in your MAMP directory and the one in var/mysql
PHP

Let me know if you enjoyed it!

The tutorial

Share this post

5 Responses

    1. Ik ben ooit eens begonnen met Yii, maar omdat ik Cake gewend was ben ik teruggekeerd.
      Cake heeft wel een steile leercurve, maar eenmaal je dat overwonnen hebt is het wel super krachtig!

        1. ik denk dat je dan dringend eens je bronnen moet herchecken, CakePHP v2.x is PHP5 only.

          Te weinig kracht wil ik wel eens in cijfers zien met een vergelijkende benchmark of met onderbouwde argumenten!

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts