This article is 13 years old
The content here might be outdated as technology and best practices evolve quickly. While the concepts may still be valuable, please verify the information against current documentation and standards.
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
-
Downloading CakePHP
-
Creating database tables
-
Generate Models based on database tables, controllers and views
-
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
About the Author
👋 Hi, I'm Frederik Jacques, a passionate iOS developer and entrepreneur with over a decade of experience building innovative mobile applications.
I love creating apps that solve real problems and bring joy to users. From educational tools to creative meme makers, I'm always exploring new ways to blend technology with user experience. When I'm not coding, you'll find me sharing insights about iOS development, app monetization, and the indie developer journey.