Today we will be going over the basic setup and configuration of the rapid application framework CakePHP. Actual cakephp development will be covered over a series of tutorials, but for this one, we will be getting the environment ready for future use. It is an easy and simple process, and does not take huge amounts of time. That is the beauty of such frameworks: Rapid Development and Deployment.
For this tutorial, we will need to setup a local development environment first. Luckily, our good friend The Fattest has made such a tutorial for us. In the Setting up a local drupal development environment, we are taken through all the steps to create a local server to play around with. You have to do the same thing for this tutorial, so go on and read through. For our tutorial, however, we need a database named cakephp. We also will not need a virtual host or drupal, so you can skip those sections. If you did everything correctly, you should end up with a local server with mod_rewrite enabled and a mysql database named cakephp.
Database Configuration
While you are in phpmyadmin, you might as well go ahead and add a table to work with. For the first couple of tutorials, we will need Products table with 4 columns. Once you have created your database, you are automatically taken to the databases "page", where you can conveniently create tables. All you need to do is put in the table name, number of fields (in this case 4), and smash go. Then you are taken to fill in the field information. Refer to the image below for the information you need to fill in, make sure you copy it exactly.
New Table Form
Since we have a table now, we should go ahead and put some data in there. All you need to do is click on the Insert tab, fill in the information, and hit go. Make sure you uncheck the Ignore checkbox so you can add two records. You can fill in whatever you like, but don't fill in the id field, if you did everything correctly it should fill in automatically. Once you have some basic data in there, you will be ready to move on.
PHPMyAdmin insert tab
Install CakePHP
Ok, now that the database is squared away, you need to download cakePHP, which you can't really miss on their site. Once you have it downloaded, all you have to do is put the cake folder in your root www directory or anywhere available on your local server. And that's it. Not real installation, just a few files to copy and settings to configure.
Now that you have cake on your server, you can actually go to localhost/cakephp_directory and you will see the nice default cakephp page. While it is interesting to see what cake can do without touching it, you have to setup a database configuration to get things going.
Cake's Database Configuration
First you need to make a copy of the database.php.default configuration file found in cake_directory/app/config. Make sure you make a copy inside the same folder, after that just take off the .default and you have you blank configuration file. Using you favorite text or code editor, open it up, and after scrolling down a bit, you should see:
{
var $default = array('driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'project_name',
'prefix' => '');
var $test = array('driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'project_name-test',
'prefix' => '');
}
First off, you probably notice there is actually two database setups there. This is because cake can actually handle more than just one database at a time, you can even add more than two. For our purposes, however, we need only one, so you can delete the second one. Most of the stuff should be pretty straight forward, with our complete database config file looking like so:
{
var $default = array('driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'cakephp',
'prefix' => '');
}
If you open up your cake app in a browser you will see the default cake page, with two extra messages letting you know that you database is setup and connectible. This is really good news, and means that we are pretty much ready to start building our first app. But that is for the next tutorial. For now you can take a break, and be glad your cake app is ready to be built. That's it for this one, but don't forget that when you need some programming assistance, just Switch On The Code.
Database config messages on the cake home page
10/20/2008 - 19:29
Is this the new 1.2 RC3? The screenshots look like the old version.
10/21/2008 - 07:19
Well, it may seem like an older version but I downloaded the latest stable release not 10 minutes before I started this tutorial on the 17th. Which is actually 1.1.20.
05/12/2010 - 04:12
this is really a very good tutorial for cake php beginners thank you for this tutorial... Expecting more tutorial like this for cake php.
10/30/2010 - 01:24
iam running a php application thts based on cake php frame work...on running the script iam getting a message as follows: NrQuery Error Affected Num. rows Took (ms)
04/30/2011 - 06:25
it is little tough to learn
Add Comment
[language] [/language]
Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]
See here for supported languages.
Javascript must be enabled to submit anonymous comments - or you can login.