Proyek

Google

Saturday, December 15, 2007

Cake's Scaffolding is Pretty Cool

So cool that you'll want to use it in production apps. Now, we think its cool, too, but please realize that scaffolding is... well... just scaffolding. It's a bunch of stuff you throw up real quick during the beginning of a project in order to get started. It isn't meant to be completely flexible. So, if you find yourself really wanting to customize your logic and your views, its time to pull your scaffolding down in order to write some code.

Scaffolding is a great way of getting the early parts of developing a web application started. Early database schemas are volatile and subject to change, which is perfectly normal in the early part of the design process. This has a downside: a web developer hates creating forms that never will see real use. To reduce the strain on the developer, scaffolding has been included in Cake. Scaffolding analyzes your database tables and creates standard lists with add, delete and edit buttons, standard forms for editing and standard views for inspecting a single item in the database. To add scaffolding to your application, in the controller, add the $scaffold variable:

class CategoriesController extends AppController
{
var $scaffold;
}
?>

One important thing to note about scaffold: it expects that any field name that ends with _id is a foreign key to a table which has a name that precedes the underscore. So, for example, if you have nested categories, you'd probably have a column called parent_id. With this release, it would be best to call this parentid. Also, when you have a foreign key in your table (e.g. titles table has category_id), and you have associated your models appropriately (see Understanding Associations, 6.2), a select box will be automatically populated with the rows from the foreign table (category) in the show/edit/new views. To set which field in the foreign table is shown, set the $displayField variable in the foreign model. To continue our example of a category having a title:

class Title extends AppModel
{
var $name = 'Title';

var $displayField = 'title';
}
?>

referer : http://manual.cakephp.org

Thursday, December 13, 2007

Config Database in Cakephp

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 last time you configure anything.

A copy of Cake's database configuration file is found in /app/config/database.php.default. Make a copy of this file 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 that apply 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 Cake welcome page. It should also tell you that your database connection file was found, and that Cake can successfully connect to the database.

Introduce to Cakephp

Introduction

Welcome to Cake! You're probably checking out this tutorial because you want to learn more about how Cake works. Its our aim to increase productivity and make coding more enjoyable: we hope you'll see this as you dive into the code.

This tutorial will walk you through the creation of a simple blog application. We'll be getting and installing Cake, 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 using other servers should be very similar. We might have to play a little with the server configuration, but most 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 about SQL 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 if you're a procedural fan.

  4. Finally, you'll need a basic knowledge of the MVC programming pattern. A quick overview can be found in Chapter "Basic Concepts", Section 2: The MVC Pattern. Don't worry: its only a half a page or so.

Let's get started!


Getting Cake

First, let's get a copy of fresh Cake code.

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
.htaccess
index.php
VERSION.txt

Now might be a good time to learn a bit about how Cake's directory structure works: check out Chapter "Basic Concepts"

From : http://cakephp.org

Welcome

Apa itu Cakephp? Cake adalah sebuah Framework PHP, yang sangat bermanfaat untuk membuat aplikasi berbasis web khususnya PHP secara cepat.

Hot Features:

Model, View, Controller Architectur
View Helpers untuk AJAX, Javascript, HTML Forms
terdapat Validation
Application Scaffolding
Application dan CRUD code generation menggunakan Bake
Access Control Lists
Data Sanitization
Security, Session, dan Request Handling Components
Flexible View Caching