There has been tremendous progress in the PHP world in the last five years. CakePHP is a program that can very quickly generate PHP Code for you, creating modules and functions in an object oriented programming format. It is very easy for you to modify this code. It is based on the Model, View, Controller (MVC) philosophy:
To install CakePHP get all the usual LAMP modules, i.e.:
apt-get install apache2 php5 mysql-client mysql-server php-mysql
Restart Apache2 to be safe with the command:
Fetch the tarred file with the command below:
Note, your version may be newer, at the time of this writing 1.2.5 was the most recent version.
tar -zxvpf cake_1.2.5.tar.gz
After untaring using the above command, this will create a new directory cake_1.2.5/ Now, type:
mv cake_1.2.5/* cake_1.2.5/.htaccess /var/www/cakephp
to move all the cakephp files and the .htaccess file to the web directory above. The CakePHP documentation is really good so I suggest following it to install a practice blog using this. Follow all the procedures you used when installing Drupal and Joomla to create a SQL database, define a user and a password. You can see this by clicking on the Drupal link. Note, a few of the modules have blank lines in the PHP scripts. Make sure you delete all the blank lines especially at the end of the PHP page as this can cause problems later. Note, once you are all done, you can remove the sql query line at the bottom by going to the /var/www/cakephp/app/config/core.php and changing the debug level to 0 as in:
You will also need to modify the routes.php file to make it point to your database and not the default built in one for displaying CakePHP documentation as in:
Router::connect ('/', array('controller'=>'posts', 'action'=>'index'));
Lastly for your reference here are all the files documented that I used . Note, all the files are under the /var/www/cakephp directory:
Note, I had trouble getting the CakePHP program to recognize that I had Mod_Rewrite enabled in Apache2.
So I used the known work around that you will see in the core.php file:
* To configure CakePHP *not* to use mod_rewrite and to
* use CakePHP pretty URLs, remove these .htaccess
* And uncomment the App.baseUrl below:
Once you have mastered the above. The next step is to use the built in bake code generator.
It is amazing what you can do. Here is an incredibly well written book on
Your first command at the terminal will be:
cake bake -app /var/www/cakephp/app
If you did not create a database.php file, start off by selecting D for Database configuration file
Next, select C for Controller file
When it asks: Would you like to use scaffolding? (y/n) , select [n] for no .
When it asks: Would you like to include some basic class methods (index(), add(), view(), edit())? (y/n) , select [y] for yes.
Say no to admin routing , when prompted.
Say no to helpers and componets and yes to sessions when prompted.
Next, you will create the Model .
Say Yes to validation putting in appropriate values, i.e. body must be not-empty etc.
Say No to model associations for now, keeping it simple. You can modify later.
Next, you will create the View .
Say No to scaffolding , when it asks you. For a camel cased Function Name pick something like:
Action Name? (use camelCased function name) > AddPost You will then see:
The following view will be created:
Controller Name: Posts
Action Name: AddPost
The last thing to do, is make the tmp directory under app be writeable with:
/var/www/cakephp/app/# chmod 777 -R tmp/
To launch type:
http://localhost/cakephp/index.php Note, this is similar to what we did, by hand earlier. I am attaching all the files here so you can compare them.