I had first heard the name around 3 months back, didn’t get a chance to try it until this weekend, and my my! they have really taken MVC to the extreme…
I was playing around with version 1.2.x.x on my Ubuntu Machine, here’s an overview of what I had:
- CakePHP 1.2.x.x
- PHP5
- MySQL5
- Apache2.2 (running on Ubuntu Fiesty)
Here’s what I did:
Install CakePHP:
- I downloaded Cake’s latest version (1.2.0.5427alpha to be specific) from CakePHP’s site and extracted into /var/www (so that my app path looked like /var/www/cake/app)
- Followed the Tutorial :Installing cakePHP on Ubuntu
Points:
- You may consider downloading the manual and api docs as well, (unfortunately there’s no manual for version 1.2.x.x as of yet, but the old one still serves as a good resource to start with)
- The Tutorial asks you to set DocumentRoot to /var/www/app/webroot, but if you keep the default directory structure, your webroot is actually sitting at /var/www/cake/app/webroot and this is where you should point your DocumentRoot to.
- Although the tutorial recommends to point your DocumentRoot to the app/webroot, I don’t recommend it for development machines which have a lot of other stuff installed in their DocumentRoot e.g. I have phpMyAdmin at /var/www/pma (http://localhost/pma), so I did not change the DocumentRoot. The only difference is that my cake url becomes http://localhost/cake instead of http://localhost which is alright with me, after all it’s a development machine.
Configure CakePHP:
By now, CakePHP should be up and running except that it might be raising some warnings (app/tmp not writable, db not present, etc). These solutions are quiet straight forward:
- To make tmp writable:
sudo chmod -vR 777 /var/www/cake/app/tmp
(I have made it globally writable, it should rather be writable only be the user the webserver runs as)
- Make changes to the config files inside app/config, specifically you need to provide a database.php (can be copied from database.php.default), and change the Session String constant.
CakePHP should be running warning-free now.
Read a Tutorial to get familiar:
- You may follow the Blog Tutorial or the User Authentication Example (both part of the manual if you downloaded it earlier) to get familiar with the framework, If you are new to MVC, you may consider reading the Basic Concepts chapter of the manual.
Setup the Console:
Then I set up the Console, which means adding the path to $PATH variable, if you can’t figure out, check this screencast.
Integrate with Eclipse:
- Use this: Setting up Eclipse to work with Cake
Points:
- Although this tutorial addresses a Windows environment, the steps are essentially the same (except the Console setup, which you have already done)
Use Bake to create a skeleton application:
- Using Bake is very straight forward, you just need to issue the following command from the app folder:
cake bake
and it takes you through a step by step procedure to create a skeleton for your Models, Controllers and Views. For a start, you may only create models and Controllers (with scaffolding ON)
Points:
- Make sure you don’t use a class name that conflicts one of the CakePHP’s core class names, I happend to name a model as “File” and ran into all sorts of errors. Specifically it’ll give you something like:
Notice (8) Undefined property: File::$table[CORE/cake/libs/model/model.php, line 640]
along with other bad things. You can check the api docs to make sure your class names don’t conflict with those of CakePHP’s.- Bake is not the only shell, there are a number of others, their list is provide when you use:
cake- Do some exploration to get yourself fully understand the functionality you have at your hand.
Resources:
- You should join CakePHP Google Group to ask questions
- Cake Bakery is a good resource for tutorials and code snippets.
- Cake Screencasts are another good resource.
My target for next weekend is to explore simpletest for unit testing CakePHP apps. I’ll try to post my experience here. =)