CakePHP Programmer's Reference Guide

A Rapid Development Framework

Cake Software Foundation Inc.

John Anderson

Author and Editor

Larry E Masters

Author and Technical Editor

Version 1.x.x.x (Incomplete)

This work is licensed under the NEED TO CHOOSE LICENSE; you can see the full terms of the license here.

This is the official manual

These conditions may only be waived with prior consent from the Cake Software Foundation Inc..

Revision History
Revision 0.1 $Date: 2006-06-20 08:16:48 +0100 (ter, 20 Jun 2006) $

Pre-release Preview

Abstract

This is the official CakePHP manual,


Table of Contents

Preface
1. Audience
2. CakePHP is Free
3. Community
1. Introduction to CakePHP
1.1. What is CakePHP?
1.2. Why CakePHP?
1.3. History of CakePHP
2. Basic Concepts
2.1. Introduction
2.2. The MVC Pattern
2.3. Overview of the Cake File Layout
3. Installing CakePHP
3.1. Introduction
3.2. Requirements
3.2.1. Server Requirements
3.3. Installing CakePHP
3.3.1. Getting the most recent stable version
3.3.2. Unpacking
3.4. Setting Up CakePHP
3.4.1. Development Setup
3.4.2. Production Setup
3.4.3. Advanced Setup: Alternative Installation Options
3.5. Configuring Apache and mod_rewrite
3.6. Make Sure It's Working
4. Configuration
4.1. Database Configuration
4.2. Global Configuration
4.3. Routes Configuration
4.4. Advanced Routing Configuration: Admin Routing and Webservices
4.5. (Optional) Custom Inflections Configuration
5. Scaffolding
5.1. Cake's Scaffolding is Pretty Cool
5.2. Customizing Scaffold Views
6. Models
6.1. What is a model?
6.2. Model Functions
6.2.1. User-Defined Functions
6.2.2. Retrieving Your Data
6.2.3. Complex Find Conditions (using arrays)
6.2.4. Saving Your Data
6.2.5. Model Callbacks
6.3. Model Variables
6.4. Associations
6.4.1. Introduction
6.4.2. Defining and Querying with hasOne
6.4.3. Defining and Querying with belongsTo
6.4.4. Defining and Querying with hasMany
6.4.5. Defining and Querying with hasAndBelongsToMany
6.4.6. Saving Related Model Data
6.4.7. Saving hasAndBelongsToMany Relations
6.4.8. Changing Associations on the Fly using bindModel() and unbindModel()
7. Controllers
7.1. What is a controller?
7.2. Controller Functions
7.2.1. Interacting with your Views
7.2.2. User Redirection
7.2.3. Controller Callbacks
7.2.4. Other Useful Functions
7.3. Controller Variables
7.4. Controller Parameters
8. Views
8.1. Views
8.1.1. Layouts
8.1.2. Elements
9. Components
9.1. Presentation
9.2. Creating your own
9.3. Making your components public
10. Helpers
10.1. Helpers
10.1.1. HTML
10.1.2. AJAX
10.1.3. Javascript
10.1.4. Number
10.1.5. Text
10.1.6. Time
10.1.7. Cache
10.2. Creating Your Own Helpers
10.2.1. Extending the Cake Helper Class
10.2.2. Including other Helpers
10.2.3. Using your Custom Helper
10.2.4. Contributing
11. Cake's Global Constants And Functions
11.1. Global Functions
11.2. CakePHP Core Definition Constants
11.3. CakePHP Path Constants
11.4. CakePHP Webroot Configuration Paths
12. Data Validation
12.1. Data Validation
13. Plugins
13.1. Creating a Plugin
13.2. Plugin Controllers
13.3. Plugin Models
13.4. Plugin Views
13.5. Working With Plugins
14. Access Control Lists
14.1. Understanding How ACL Works
14.2. Defining Permissions: Cake's INI-based ACL
14.3. Defining Permissions: Cake's Database ACL
14.3.1. Getting Started
14.3.2. Creating Access Request Objects (AROs) and Access Control Objects (ACOs)
14.3.3. Assigning Permissions
14.4. Checking Permissions: The ACL Component
15. Data Sanitization
15.1. Using Sanitize in Your Application
15.2. Making Data Safe for use in SQL and HTML
16. The Cake Session Component
16.1. Cake Session Storage Options
16.2. Using the Cake Session Component
17. The Request Handler Component
17.1. Introduction
17.2. Getting Client/Request Information
17.3. Stripping Data
17.4. Other Useful Functions
18. The Security Component
18.1. Introduction
18.2. Protecting Controller Actions
18.3. Handling Invalid Requests
18.4. Advanced Request Authentication
19. View Caching
19.1. What is it ?
19.2. How Does it Work ?
19.2.1. Activating the cache
19.2.2. The $cacheAction Controller Variable
19.2.3. Marking Content in the View
19.2.4. Clearing the cache
19.3. Things To Remember
A. The Cake Blog Tutorial
A.1. Introduction
A.2. Getting Cake
A.3. Creating the Blog Database
A.4. Cake Database Configuration
A.5. A Note On mod_rewrite
A.6. Create a Post Model
A.7. Create a Posts Controller
A.8. Creating Post Views
A.9. Adding Posts
A.10. Data Validation
A.11. Deleting Posts
A.12. Editing Posts
A.13. Routes
A.14. Conclusion
B. Example: Simple User Authentication
B.1. The Big Picture
B.2. Authentication and Persistence
B.3. Access Checking in your Application
C. Cake Conventions
C.1. Conventions, eh ?
C.2. Filenames
C.3. Models
C.4. Controllers
C.5. Views
C.6. Helpers
C.7. Components
C.8. Vendors

List of Tables

6.1. Model::recursive options

List of Examples

3.1. Suggested Production httpd.conf
3.2. /app/webroot/index.php (partial, comments removed)
4.1. app/config/database.php
4.2. Route Pattern
4.3. Route Example
4.4. Route Handling in a Controller
4.5. Setting the Default Route
4.6. /app/config/core.php (partial)
4.7. messages_controller.php
5.1. Custom Scaffolding Views for a Single Controller
5.2. Custom Scaffolding Views for an Entire Application
6.1. Example User Model, saved in /app/models/user.php
6.2. Example Model Functions
6.3. Custom Sql Calls with query()
6.4. Basic find conditions array usage example:
6.5. /app/models/user.php hasOne
6.6. /app/models/profile.php belongsTo
6.7. /app/models/user.php hasMany
6.8. HABTM Join Tables: Sample models and their join table names
6.9. /app/models/post.php hasAndBelongsToMany
6.10. /app/controllers/posts_controller.php (partial)
6.11. /app/controllers/posts_controller.php (partial)
6.12. /app/views/posts/add.thtml Form for creating posts
6.13. /app/views/posts/add.thtml (Tag association code added)
6.14. leader.php and follower.php
6.15. leaders_controller.php (partial)
6.16. Generic unbindModel() example
6.17. leaders_controller.php (partial)
6.18. Generic bindModel() example
8.1. Calling an Element without parameters
8.2. Calling an Element passing a data array
9.1. A simple component
10.1. Edit Action inside of the NotesController
10.2. Edit View code (edit.thtml) sample
10.3. Concatenating time data before saving a model (excerpt from NotesController)
10.4. AjaxHelper $options Keys
10.5. /app/views/helpers/link.php
10.6. /app/views/helpers/link.php (logic added)
10.7. /app/views/helpers/link.php (using other helpers)
12.1. /app/models/user.php
12.2. Form-handling Action in /app/controllers/blog_controller.php
12.3. The add form view in /app/views/blog/add.thtml
13.1. Pizza Ordering Filesystem Layout
13.2. Pizza Plugin AppController: /app/plugins/pizza_app_controller.php
13.3. Pizza Plugin AppModel: /app/plugins/pizza_app_model.php
13.4. /app/plugins/pizza/controllers/pizza_orders_controller.php
13.5. /app/plugins/pizza/models/pizza_order.php
13.6. /app/plugins/pizza/views/pizza_orders/index.thtml
14.1. Initializing your database using acl.php
16.1. core.php Session Configuration
19.1. /app/config/core.php (partial)
19.2.
19.3. $cacheAction Examples
19.4. <cake:nocache> example
19.5. <cake:nocache> example
A.1. /app/models/post.php
A.2. /app/controllers/posts_controller.php
A.3. /app/controllers/posts_controller.php (index action added)
A.4. /app/views/posts/index.thtml
A.5. /app/controllers/posts_controller.php (view action added)
A.6. /app/views/posts/view.thtml
A.7. /app/controllers/posts_controller.php (add action added)
A.8. /app/views/posts/add.thtml
A.9. /app/models/post.php (validation array added)
A.10. /app/controllers/posts_controller.php (delete action only)
A.11. /app/views/posts/index.thtml (add and delete links added)
A.12. /app/controllers/posts_controller.php (edit action only)
A.13. /app/views/posts/edit.thtml
A.14. /app/views/posts/index.thtml (edit links added)
B.1. Table 'users', Fictional Client Management System Database
B.2. /app/views/users/login.thtml
B.3. /app/controllers/users_controller.php (partial)
B.4. /app/app_controller.php
B.5. Forcing authentication before all actions in a controller
B.6. Forcing authentication before a single controller action