Using CakePHP Framework is one of my most favorite things to do. This is the first PHP framework I worked with, and until now, I'm still delighted by it. Now it is time for me to share my knowledge in CakePHP web development.
I think you are here because you already know what CakePHP is, but for those who has no idea yet, and don't want to read more on CakePHP.org, here's a brief description: CakePHP makes building web applications simpler, faster and require less code.
I think there are really few blog posts out there with regards to beginner CakePHP tutorials. Most of them are also outdated. We will keep this CakePHP posts as updated as possible. So to the future reader of these posts, please drop something in the comment section below if you think there is something outdated!
We will start with the most basic thing to advanced. Hopefully I can finish this tutorial series in the shortest time possible.
2.0 Install CakePHP on Your Server
By the way, if you're a super beginner and using a windows PC (localhost), you can follow this tutorial first to set up your localhost: 3 Steps to Install WAMP on Windows
2.1 Download CakePHP (Step 1)
As of this writing, the version is CakePHP 2.3.6 stable.
Extract the ZIP file.
2.2 Put CakePHP on Your Hosting (Step 2)
After you download and extract the Framework files, you have to put it in your root directory. I'm using windows 8 and running with WAMP server, so in my case, my root directory is in:
Now after putting the extracted folder, my CakePHP directory is in:
Of course, we want to change the dirty name "cakephp-cakephp-b81c198" to our "project name".
So we have to rename it and for this tutorial, we will name it "CakePhpProj", awesome name right? If you don't think so, you can choose the project name of your choice. Now we should have:
2.3 Run CakePHP
So to run CakePHP: Go to your browser > type "localhost/CakePphProj"
You might see something beautiful like this:
You might be disappointed or intimidated by now, but don't worry, I'm at your side! Proceed to the next step below.
2.4 Configure CakePHP
Alright, so we're going to address the issues on the previous screenshot, one at a time!
2.4.1 URL rewriting is not properly configured on your server.- Let's start with this problem, this error is rare if you're using a real hosting. But if you're using localhost, here's the fix:
1. On you notification area (lower right corner), click the WAMP icon.
2. Hover your mouse to the "Apache" folder
3. Hover your mouse to the "Apache modules" folder
4. Find and click "rewrite_module", WAMP will automatically restart and check that apache module.
2.4.2 Please change the value of 'Security.salt' - To solve this, you have to to got the core.php file and just change the security salt string!
In my case, I have to open it in C:\wamp\www\CakePhpProj\app\Config\core.php
Find the word "salt" (Ctrl+F on your editor, I'm using notepad++)
You should see the line of code that looks like:
Change the value to something like:
Then re-run the browser:
2.4.3 Please change the value of 'Security.cipherSeed' - The solution is the same with 2.4.2, just change the value and re-run!
2.4.4 Your database configuration file is NOT present. - Now we have to make a database for our CakePHP application. If you need help doing that, here's a guide: How To Create MySQL Database With PhpMyAdmin
After creating a database, we have to go again to the Config directory, in my case:
Now you should see a file named "database.php.default" and rename it to just "database.php"
After renaming it, we have to open it with our editor and supply the database details! In the $default array, what usually we have to change are the: database host, login (username), password and database
You would see something like this in default:
public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'user', 'password' => 'password', 'database' => 'database_name', 'prefix' => '', //'encoding' => 'utf8', );
So we're going to change it to:
public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => 'my_project_database', 'prefix' => '', //'encoding' => 'utf8', );
Now, re-run our project page in the browser, it should look like this:
Still having hard time? I can personally help you do this for only $5!
That's it for this post, enjoy and continue your CakePHP web development! Here is a continuation of this post: CakePHP Classes and Naming Conventions
For FREE programming tutorials, click the red button below and subscribe! :)