CakePHP Beginner Tutorial – Part1
I am writing this CakePHP Beginner tutorial for my friends, who are interested to code MVC style. Welcome to CakePHP – MVC Framework. Here is your CakePHP Beginner Tutorial to create a sample Application.
Step #1 Download Latest CakePHP files from here or use this Direct File Link (cake_1.2.0.7125-rc1.zip)
Step #2 I hope you have PHP configured and you are able to see what is <?php echo “Hi Karthik”; ?>
Step #3 Lets assume your “DOCUMENT_ROOT” is k:\www\ Extract cakephp files to k:\www\kake\ So, Your directory arch will look alike.. k:\www\kake\app k:\www\kake\cake ….
Step #4: Create a MySQL database called “cakedb” & a table “members”
CREATE TABLE `members` (
`id` INT( 12 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 32 ) NOT NULL , `email` VARCHAR( 45 ) NOT NULL) ENGINE = innodb;
Step #5: This is the most important part you have to understood. We are gonna create Models/Controllers/Views using commandline. Dont do this step without understanding the basics of MVC concept.
++++++++++++++++++++++++++++++
Start -> Run -> Cmd (*nix users use your terminal)
C:\>k: k:\>cd www\kake\cake\console\
k:\www\kake\cake\console\>path K:\wamp\bin\php\php5.2.5 (Linux users: #php or #/usr/bin/php . orĀ know your php ps path from #which php command)
Step #6: Lets do it. (This part is very simple to do, I am not gonna provide you a screenshot or anything… I will give you a raw idea.. As you are a programmer is good to learn this progress as “trial & error” method
k:\www\kake\cake\console\>cake bake
- Put your app path (Ex: k:\www\kake\)
- Select Database type (Ex: mysql)
- Give Database login info (Ex: host: localhost , user: root , password: >>Password is empty)
- confirm the database info
- again, k:\www\kake\cake\console\>cake bake
- We are gonna create a Model now. So press “M”
- Our table name “1.Member”(members is the table name, But cakephp suggests Model name as Singular & first letter uppercased table name)
- Press “1″
- We dont need any validation checks at this time just press “N”
- Confirm Model looks ok. Press Y
- again, k:\www\kake\cake\console\>cake bake
- Now select controller, Press C
- 1. members (table name will be your controller name)
- press “1″
- We do NOT need scaffolding (N)
- We do NOT need Test suite (N)
- We do NOT need Admin routing (N)
- We may need sessions (Y)
- We need Add/Edit/View/Delete (Y)
- Yeah, Looks ok.. Confirm the controller.
- again, k:\www\kake\cake\console\>cake bake
- We gonna do “Views” Press “V”
- again select our controller 1. members.. Press “1″
- We do need Add/Edit/View/Delete (Y)
- We do not need AdminRouting (N)
- Confirm it and exit the command line…
Looks lengthy??? Yes Ofcourse.. But it is better than writing hundereds of mysql_query(); mysql_fetch_array(); stripslashes(); again and again
yes.
Step #7 Point your browser to http://localhost/kake/index.php You will see a “Welcome message from CakePHP” Wait, It may look very dry without any color. You have to configure CakePHP *not* to use mod_rewrite. So
open k:\www\kake\app\config\core.php
Uncomment: Configure::write(‘App.baseUrl’, env(‘SCRIPT_NAME’)); line.
Now, Refresh your browser.. it may look better.
Step #8: Visit : http://localhost/kake/index.php/members You can see a list of members and you can add members on http://localhost/kake/index.php/members Post your doubts here.. I am glad to help you. Regards, Karthik

One Response so far
May 24th, 2010
4:06 am
hi karthi….
how r u?now a day i saw u r full profile, r u really great, how many websites are u created, all are the very useful, specially techtamil..This site is very super(specially u r us trip photos). and one request, i saw u r cake php installation in text formate it is good…. i have some doubts in the installation so, pls send the video formate(like techtamil videos).
my contact: mailid:victor_2k10@yahoo.com
Leave a comment
You must be logged in to post a comment.