CakePhp Manual

download CakePhp  Manual

of 141

  • date post

    18-Nov-2014
  • Category

    Documents

  • view

    114
  • download

    0

Embed Size (px)

description

For cake php developper

Transcript of CakePhp Manual

CakePHPA Rapid Development Framework

Cake Software Foundation Inc. Author and Editor: John Anderson Author and Technical Editor: Larry E Masters

CakePHP Programmer's Reference Guideby Cake Software Foundation Inc. Author and Editor: John Anderson Author and Technical Editor: Larry E Masters Version 1.x.x.x (Incomplete) Copyright 2006 Cake Software Foundation Inc.

AbstractThis is the official CakePHP manual,This work is licensed under the NEED TO CHOOSE LICENSE; you can see the full terms of the license here [http://www.cakephp.org]. This is the official manual These conditions may only be waived with prior consent from the Cake Software Foundation Inc..

Table of ContentsPreface .............................................................................................................. x 1. Audience ................................................................................................................ x 2. CakePHP is Free .................................................................................................... x 3. Community ............................................................................................................. x 1. Introduction to CakePHP ................................................................................. 1 1.1. What is CakePHP? ............................................................................................... 1 1.2. Why CakePHP? ................................................................................................... 1 1.3. History of CakePHP ............................................................................................. 1 2. Basic Concepts ............................................................................................... 2 2.1. Introduction .......................................................................................................... 2 2.2. The MVC Pattern ................................................................................................. 2 2.3. Overview of the Cake File Layout .......................................................................... 2 3. Installing CakePHP ......................................................................................... 4 3.1. Introduction .......................................................................................................... 4 3.2. Requirements ...................................................................................................... 4 3.2.1. Server Requirements ......................................................................................... 4 3.3. Installing CakePHP .............................................................................................. 4 3.3.1. Getting the most recent stable version ................................................................ 4 3.3.2. Unpacking ......................................................................................................... 4 3.4. Setting Up CakePHP ............................................................................................ 5 3.4.1. Development Setup ........................................................................................... 5 3.4.2. Production Setup ............................................................................................... 5 3.4.3. Advanced Setup: Alternative Installation Options ................................................. 6 3.5. Configuring Apache and mod_rewrite .................................................................... 8 3.6. Make Sure It's Working ......................................................................................... 8 4. Configuration .................................................................................................. 9 4.1. Database Configuration ........................................................................................ 9 4.2. Global Configuration ........................................................................................... 10 4.3. Routes Configuration .......................................................................................... 11 4.4. Advanced Routing Configuration: Admin Routing and Webservices ....................... 12 4.5. (Optional) Custom Inflections Configuration ......................................................... 14 5. Scaffolding ................................................................................................... 15 5.1. Cake's Scaffolding is Pretty Cool ......................................................................... 15 5.2. Customizing Scaffold Views ................................................................................ 15 6. Models ......................................................................................................... 17 6.1. What is a model? ............................................................................................... 17 6.2. Model Functions ................................................................................................. 17 6.2.1. User-Defined Functions ................................................................................... 18 6.2.2. Retrieving Your Data ....................................................................................... 18 6.2.3. Complex Find Conditions (using arrays) ............................................................ 21 6.2.4. Saving Your Data ............................................................................................ 23 6.2.5. Model Callbacks .............................................................................................. 24 6.3. Model Variables ................................................................................................. 26 6.4. Associations ...................................................................................................... 27 6.4.1. Introduction ..................................................................................................... 27 6.4.2. Defining and Querying with hasOne .................................................................. 28 6.4.3. Defining and Querying with belongsTo .............................................................. 29 6.4.4. Defining and Querying with hasMany ................................................................ 30 6.4.5. Defining and Querying with hasAndBelongsToMany .......................................... 33 6.4.6. Saving Related Model Data .............................................................................. 36 6.4.7. Saving hasAndBelongsToMany Relations ......................................................... 37 6.4.8. Changing Associations on the Fly using bindModel() and unbindModel() ............. 39 7. Controllers .................................................................................................... 43 7.1. Controller Functions ........................................................................................... 43 7.1.1. Interacting with your Views ............................................................................... 44 7.1.2. User Redirection ............................................................................................. 44 iv

CakePHP

7.1.3. Controller Callbacks ........................................................................................ 45 7.1.4. Other Useful Functions .................................................................................... 45 7.2. Controller Variables ............................................................................................ 48 7.3. Controller Parameters ........................................................................................ 49 8. Views ........................................................................................................... 51 8.1. Views ................................................................................................................ 51 8.1.1. Layouts ........................................................................................................... 51 8.1.2. Elements ........................................................................................................ 52 9. Components ................................................................................................. 54 9.1. Presentation ...................................................................................................... 54 9.2. Creating your own .............................................................................................. 54 9.3. Making your components public .......................................................................... 55 10. Helpers ....................................................................................................... 56 10.1. Helpers ............................................................................................................ 56 10.1.1. HTML ........................................................................................................... 56 10.1.2. AJAX ............................................................................................................ 62 10.1.3. Javascript ..................................................................................................... 67 10.1.4. Number ......................................................................................................... 68 10.1.5. Text .............................................................................................................. 69 10.1.6. Time ............................................................................................................. 70 10.1.7. Cache ........................................................................................................... 72 10.2. Creating Your Own Helpers .............................................................................. 72 10.2.1. Extend