CakePHP Newbie Series: Intro

When I picked up CakePHP and started learning how to use this incredible framework I was at a loss for words to how spread out and scattered the documentation was. A lot has changed since then with the release of the Cake Book and other various help sites, but it is still hard to a beginner to jump up onto the CakePHP learning curve.  This is the first in a series of posts that will help anyone with PHP/MySQL experiance to start playing with CakePHP the way people learn best, by example.

CakePHP makes coding extremely fast and efficient, it also makes it easier in my opinion, but only after you catch on to how the framework works.

This article will focus on making a collaborative music catalog where multiple people can add to the catalog and post comments on the different songs. Everyone does a blog so I am going to do something else.

This post will show how to install CakePHP and get it ready for coding and then it will go into how we will set up the database and allow us to make our beginning pan so we know where to go in future posts. I hope you are ready because we will start the planning process right now.

First thing’s first, you need to get CakePHP! Go to their website and download the latest copy of CakePHP 1.2! If you don’t have a development environment on your computer, I highly suggest that you download XAMPP so that you can develop your cake application on your computer.

This part is only for people with XAMPP installed with Windows. To use the bake feature of CakePHP you will need to do a few extra steps.

  1. Use a fresh copy of CakePHP and put it in your C:/XAMPP directory. You should have a directory structure like this: “C:/XAMPP/cake1.2(renamed the folder to cake1.2)/cake/console”
  2. Now you need to go to your Advanced System Settings page and In your Environment Variables you will want to edit the “PATH” Variable. Add the following to the end of your PATH “;C:\xampp\php;C:\xampp\cake1.2\cake\console;” without the quotations of course.
  3. You may need to restart your computer, but open up the console and you should be able to type “cake -v” and “php -v”. If they work, then you are ready to bake!

Now we will configure our CakePHP install.

  1. Extract CakePHP from the RAR/ZIP file that you downloaded then place the folder in your webroot. Rename the folder to musiclib. (eg. if you have xampp it would look like C:/xampp/htdocs/musiclib/app)
  2. Open up core.php which is located in App/Config
  3. Change the Salt.security line to something else, anything, the more complex the better.
  4. Rename database.php.default to database.php
  5. Open up database.php and edit the file so it can access your database.
  6. Now you are set up and ready!

Obviously we are going to need a database for this so fire up your phpMyAdmin or whatever else you use and make one, I will call mine “music”.

The first table we will need to make will be our users table, we want to have our users log in to be able to manage the music library so my database table will look like:

CREATE TABLE `users` (
`id` int(8) unsigned NOT NULL auto_increment,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`avatar` int(8) NOT NULL default '0',
`joined` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,
`access` int(8) unsigned NOT NULL default '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

We wil also need a table to hold our musical library information and a category for the different genres, mine will look like:

CREATE TABLE `genres` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
`title` VARCHAR( 255 ) NOT NULL ,
`desc` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM


CREATE TABLE `songs` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
`title` VARCHAR( 255 ) NOT NULL ,
`author` VARCHAR( 255 ) NOT NULL ,
`user_id` INT( 8 ) NOT NULL ,
`genre_id` INT( 8 ) NOT NULL ,
PRIMARY KEY ( `id` ) ,
INDEX ( `user_id` , `genre_id` )
) ENGINE = MYISAM

Now that we have our database schemes, we can get to coding this thing! But I will save that for the next part of this series where we will write the user management portion of this script.

If you want to jump into coding right away make sure that you check out the new Cake Book.

If you liked this post, subscrite to my rss feed!
Follow me on Twitter!

0 Responses to “CakePHP Newbie Series: Intro”


  1. No Comments

Leave a Reply