Hello, this is my first tutorial on Cakephp that I will be doing. I'm choosing to do these tutorials by making a blog application. I chose to do the blog application because the blog video tutorial on the Cakephp website doesn't work for me and I thought other people could benefit from a video tutorial. I chose to do these on Cakephp because I think a lot of people are intimidated by Cakephp's conventions and restrictions when first choosing a framework. I think once you understand Cake's way of doing things you will appreciate these conventions.
You can also watch this tutorial on youtube.
The first thing you should do is download the Cakephp framework from their website by clicking the big download button. After downloading the framework you can extract the frameworks files and folders into your localhosts webroot. In my case on windows this is under my C drive and I put the framework inside another directory called tut_blog, the full path for my machine using wamp is:
And I just copied/pasted all the files and folders from the download into that tut_blog directory.
Now you can go to your browser and type in the following URL to access your cake installation:
The next thing we need to do is change our database config file and connect it to our database. I've already prepared a database ahead of time for this tutorial called tut_blog using phpmyadmin. You can name your database whatever you'd like. To edit your database config file open the Cakephp framework into your text editor and rename the database.php.default file to:
Then open database.php file in your text editor and we can set our default database information like so:database.php
var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'root', 'password' => 'root', 'database' => 'tut_blog', 'prefix' => '', );
We can now refresh our browser and notice that Cake is able to detect and connect to our database.
The next thing we need to do is edit our security.salt and cipherSeed values. These are used by Cake for hashing and encrypting/decrypting strings. The salt is a random alphanumeric string and the cipherSeed is a random string of numbers. Open up app/config/core.php and change the Security.salt to a bunch of random alphanumeric characters. And change the Security.cipherSeed to random numbers. You should not use my random characters, make sure to use your own. So about half way down we can make the following changes to our salt and cipherSeed values:app/config/core.php
Configure::write('Security.salt', '1qa3wFls7wU316BgOhRQbiCkzbj0yIbyrjx3hxgGQanSb6evR6lOB4Y4w1ww1UZ'); Configure::write('Security.cipherSeed', '1263745761230981094886724783');
Back in our browser we can refresh once more to see that Cakephp is fully set up and everything should be green and it's ready to go. If you run into problems at this point or later in the tutorial you may want to check out this article on troubleshooting Cakephp installations.
The next thing we need to do is setup our first table in our tut_blog database, or whatever you named your database. Tables in Cakephp do have a convention for naming them. You create your tables using the plural form of the name. So in our case we want a "post" table name, we should instead call it "posts" with an "s" making it plural. And thats pretty much it for table naming convetions. So were going to make a "posts" table in our database:posts table SQL
All of your tables should have an ID field. This field should be an int type, primary key, and autoincrement. I've also created a varchar field called "title" to hold the title of the post as well as a text field called "body" to hold the body content of the post. The only other interesting parts of this table are the "created" and "modified" datetime fields. Everytime we create a new post cake will populate the created field with a timestamp for us. Similarliy, everytime we modify an existing post Cake will update the modified field. We don't have to worry about it at all, Cake handles all of that for us. We only need to create the two fields with the proper names and Cake does the rest.
So after creating your "posts" table thats we all need to do to get started on our blog application. In the next tutorial we'll start by going over other naming conventions for files, classnames, and such. Thanks for reading.