How to Bake a New Project in CakePhp
I use bake to start any project of mine and therefore doesn’t mean that using it produces a complete app unless you only want a CRUD application.
This tutorial is intended for beginners in cakephp. It is still recommended that you look at the blog tutorial in cakephp manual because it has a more complete introduction for the framework.
Take note that I am using the Cakephp 1.2.0.7692 RC3 in demonstrating this little project because it is the latest release as of this writing.
What to do and what do we need to begin?
To start off, we need a project. I opted a mini-library application which consists ofBooks
Authors
Book reviews by users
Authors
Book reviews by users
The mini-library will store different books. Each books can have one or more authors and one or more reviews created by users. So we will have the following tables
authors
books
books_authors
book_reviews
users
books
books_authors
book_reviews
users
And they have the following relationships:
books can have many authors
authors can have many books
books can have many reviews
users can have many reviews
a review is owned by a book
authors can have many books
books can have many reviews
users can have many reviews
a review is owned by a book
Download the SQL and create your database.
Let’s start baking!
Since our topic is about baking, we will maximize the use of cake CLI. First, setup your environment so that it will accept the cake command. For Ubuntu users, it is already available in synaptic or use apt-getsudo apt-get install cakephp1.2-scripts
For windows users, I used this tutorial for setting up Windows.
The following steps is done in Windows so I cannot guarantee the result will be the same in Ubuntu.
Once you have setup your environment, everything is just easy. I do not think I even need to tell you what you need to do but I still will since I already started it:P
You just need to remember this steps:
- Create a project. This creates all the files and directories under the /app directory
- Configure database.php. We will do that using the command line
- Start creating your Models. As the blog tutorial mentioned, models are the bread and butter of cakephp.
- Create your controllers
- Finally, create your views
- Check your new app!
So let's start doing something and stop talking eh?
Open your command line and go to your www directory or wherever you want to create your cakephp project. Do not yet create folder for this project. So in my case, my web directory is E:\www\. Type
cake bake
It will ask you to create your project since it cannot find an existing one.
Step 1: Create project
I created mylibrary project. Here is the output.

Step 2: Configure database
Then it will ask you to create your database config. In my example, my database name is cakedemo_1.

And we're done with the installation. If you will check your files, mylibrary folder is created in E:\www. mylibrary already contains all the necessary files and folders to start building your app. To check, go to http://localhost/mylibrary.

Do we have the same result?
There were 3 things that happened here in the background.
- In mylibrary/app/config/core.php, the Security.salt was modified
- mylibrary/app/config/database.php was created
- In mylibrary/app/webroot/index.php, CAKE_CORE_INCLUDE_PATH was changed to the absolute path of your cake core library, in my case "E:www\minilib" because this is what I entered in my Path settings (remember this tutorial?) So with this, you have a centralized cakephp core library.
There you have it, a new cakephp project! Let's proceed.
Step 3: Create models, controllers and views
Next step is to create our library application. Again, type cake bake in your command line. The Interactive Bake Shell will appear to ask for more directions. You must ofcourse create first your models, then controllers and finally views. Afterwards, you should have the following files like mine:

If you already have that, congratulations! Your done!
More tricks you can try out
There are also shortcuts if you only want to create models
cake bake model
or controllers
cake bake controller
or views
cake bake view
For the next post, I'll tackle how to set up different authentication components. Till next time. Happy Baking!
Tags: applications, bake


October 24th, 2008 at 7:10 am Nice stuff . i normally only bake the models . The rest i hard code , bse cake gives me more than i need at times . Any way nice begginer tutorial .
October 24th, 2008 at 7:14 am @mzee.richo thanks
November 15th, 2008 at 6:00 pm cake bake all –> makes life a lot easy.
April 28th, 2009 at 4:51 am [...] how to bake in CakePHP For your baking needs refer to the links below Bake Utility Baking MVC Bake a new Project You could also try cake bake [...]
August 23rd, 2009 at 4:44 pm [...] How to Bake a New Project in CakePhp [...]