Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
cakephp tutorial

cakephp tutorial

Ratings:

4.5

(2)
|Views: 6,243|Likes:
Published by ibnusulaiman
cakephp tutorial for beginner
cakephp tutorial for beginner

More info:

Published by: ibnusulaiman on Apr 22, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

06/16/2009

pdf

text

original

 
The Cake Blog Tutorial
Section 1 ..................................................................................................................................................................2Introduction ..........................................................................................................................................................2Section 2 ..................................................................................................................................................................2Getting Cake ........................................................................................................................................................2Section 3 ..................................................................................................................................................................3Creating the Blog Database .................................................................................................................................3Section 4 ..................................................................................................................................................................3Cake Database Configuration ..............................................................................................................................3Section 5 ..................................................................................................................................................................4A Note On mod_rewrite .......................................................................................................................................4Section 6 ..................................................................................................................................................................4Create a Post Model .............................................................................................................................................4Section 7 ..................................................................................................................................................................5Create a Posts Controller .....................................................................................................................................5Section 8 ..................................................................................................................................................................6Creating Post Views .............................................................................................................................................6Section 9 ..................................................................................................................................................................8Adding Posts ........................................................................................................................................................8Section 10 ................................................................................................................................................................9Data Validation .....................................................................................................................................................9Section 11 ...............................................................................................................................................................11Deleting Posts ....................................................................................................................................................11Section 12 ..............................................................................................................................................................12Editing Posts ......................................................................................................................................................12Section 13 ..............................................................................................................................................................14Routes ................................................................................................................................................................14Section 14 ..............................................................................................................................................................14Conclusion .........................................................................................................................................................14
 
Section 1
Introduction
Welcome to Cake! You're probably checking out this tutorial because you want to learn more about how Cakeworks. Its our aim to increase productivity and make coding more enjoyable: we hope you'll see this as you diveinto the code.This tutorial will walk you through the creation of a simple blog application. We'll be getting and installingCake, creating and configuring a database, and creating enough application logic to list, add, edit, and delete blog posts.Here's what you'll need:1.A running web server. We're going to assume you're using Apache, though the instructions for usingother servers should be very similar. We might have to play a little with the server configuration, butmost folks can get Cake up and running without any configuration at all.2.A database server. We're going to be using mySQL in this tutorial. You'll need to know enough aboutSQL in order to create a database: Cake will be taking the reigns from there.3.Basic PHP knowledge. The more object-oriented programming you've done, the better: but fear not iyou're a procedural fan.4.Finally, you'll need a basic knowledge of the MVC programming pattern. A quick overview can befound in Chapter "Basic Concepts", Section 2: The MVC Pattern. Don't worry: its only a half a page or  so.Let's get started!
Section 2
Getting Cake
First, let's get a copy of fresh Cake code. The most recent release as of this writing is CakePHP 1.0.1.2708 is thelatest release.To get a fresh download, visit the CakePHP project at Cakeforge: http://cakeforge.org/projects/cakephp/and download the stable release.You can also checkout/export a fresh copy of our trunk code at: https://svn.cakephp.org/repo/trunk/cake/1.x.x.x/Regardless of how you downloaded it, place the code inside of your DocumentRoot. Once finished, your directory setup should look something like the following:
/path_to_document_root/app/cake/vendors.htaccessindex.phpVERSION.txt
 Now might be a good time to learn a bit about how Cake's directory structure works: check outChapter "BasicConcepts", Section 3: Overview of the Cake File Layout.
 
Section 3
Creating the Blog Database
 Next, lets set up the underlying database for our blog. Right now, we'll just create a single table to store our  posts. We'll also throw in a few posts right now to use for testing purposes. Execute the following SQLstatements into your database:
/* First, create our posts table: */CREATE TABLE posts (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,title VARCHAR(50),body TEXT,created DATETIME DEFAULT NULL,modified DATETIME DEFAULT NULL);/* Then insert some posts for testing: */INSERT INTO posts (title,body,created)VALUES ('The title', 'This is the post body.', NOW());INSERT INTO posts (title,body,created)VALUES ('A title once again', 'And the post body follows.', NOW());INSERT INTO posts (title,body,created)VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
The choices on table and column names are not arbitrary. If you follow Cake's database naming conventions,and Cake's class naming conventions (both outlined inAppendix "Cake Conventions"), you'll be able to takeadvantage of a lot of free functionality and avoid configuration. Cake is flexible enough to accomodate even theworst legacy database schema, but adhering to convention will save you time.Check outAppendix "Cake Conventions"more information, but suffice it to say that naming our table 'posts'automatically hooks it to our Post model, and having fields called 'modified' and 'created' will be automagicallymanaged by Cake.
Section 4
Cake Database Configuration
Onward and upward: let's tell Cake where our database is and how to connect to it. This will be the first and lasttime you configure anything.A copy of Cake's database configuration file is found in
/app/config/database.php.default
. Make a copy of thisfile in the same directory, but name it
database.php
.The config file should be pretty straightforward: just replace the values in the $default array with those thatapply to your setup. A sample completed configuration array might look something like the following:
var $default = array('driver' => 'mysql','connect' => 'mysql_pconnect','host' => 'localhost','login' => 'cakeBlog','password' => 'c4k3-rUl3Z','database' => 'cake_blog_tutorial' );
Once you've saved your new database.php file, you should be able to open your browser and see the Cakewelcome page. It should also tell you that your database connection file was found, and that Cake cansuccessfully connect to the database.

Activity (2)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->