Cake Manual

  • Published on
    08-Mar-2015

  • View
    16

  • Download
    0

Embed Size (px)

Transcript

<p>CakePHPA Rapid Development Framework</p> <p>Cake Software Foundation Inc. Author and Editor: John Anderson Author and Technical Editor: Larry E Masters</p> <p>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.</p> <p>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..</p> <p>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 .................................................................................................... 42 7.1. What is a controller? ........................................................................................... 42 7.2. Controller Functions ........................................................................................... 42 7.2.1. Interacting with your Views ............................................................................... 43 iv</p> <p>CakePHP</p> <p>7.2.2. User Redirection ............................................................................................. 43 7.2.3. Controller Callbacks ........................................................................................ 44 7.2.4. Other Useful Functions .................................................................................... 44 7.3. Controller Variables ............................................................................................ 47 7.4. Controller Parameters ........................................................................................ 48 8. Views ........................................................................................................... 50 8.1. Views ................................................................................................................ 50 8.1.1. Layouts ........................................................................................................... 50 8.1.2. Elements ........................................................................................................ 51 9. Components ................................................................................................. 53 9.1. Presentation ...................................................................................................... 53 9.2. Creating your own .............................................................................................. 53 9.3. Making your components public .......................................................................... 54 10. Helpers ....................................................................................................... 55 10.1. Helpers ............................................................................................................ 55 10.1.1. HTML ........................................................................................................... 55 10.1.2. AJAX ............................................................................................................ 61 10.1.3. Javascript ..................................................................................................... 66 10.1.4. Number ......................................................................................................... 67 10.1.5. Text .............................................................................................................. 68 10.1.6. Time ............................................................................................................. 69 10.1.7. Cache ........................................................................................................... 71 10.2. Creating Your Own Helpers .............................................................................. 71 10.2.1. Extending the Cake Helper Class ................................................................... 71 10.2.2. Including other Helpers .................................................................................. 72 10.2.3. Using your Custom Helper ............................................................................. 73 10.2.4. Contributing .................................................................................................. 73 11. Cake's Global Constants And Functions ....................................................... 74 11.1. Global Functions .............................................................................................. 74 11.2. CakePHP Core Definition Constants .................................................................. 77 11.3. CakePHP Path Constants ................................................................................. 78 11.4. CakePHP Webroot Configuration Paths ............................................................. 79 12. Data Validation ........................................................................................... 80 12.1. Data Validation ................................................................................................. 80 13. Plugins ....................................................................................................... 83 13.1. Creating a Plugin .............................................................................................. 83 13.2. Plugin Controllers ............................................................................................. 84 13.3. Plugin Models .................................................................................................. 85 13.4. Plugin Views .................................................................................................... 85 13.5. Working With Plugins ........................................................................................ 85 14. Access Control Lists .................................................................................... 87 14.1. Understanding How ACL Works ........................................................................ 87 14.2. Defining Permissions: Cake's INI-based ACL ..................................................... 90 14.3. Defining Permissions: Cake's Database ACL ..................................................... 90 14.3.1. Getting Started .............................................................................................. 90 14.3.2. Creating Access Request Objects (AROs) and Access Control Objects (ACOs) 91 14.3.3. Assigning Permissions ................................................................................... 92 14.4. Checking Permissions: The ACL Component ..................................................... 93 15. Data Sanitization ......................................................................................... 95 15.1. Using Sanitize in Your Application ..................................................................... 95 15.2. Making Data Safe for use in SQL and HTML ...................................................... 95 16. The Cake Session Component ..................................................................... 97 16.1. Cake Session Storage Options .......................................................................... 97 16.2. Using the Cake Session Component .................................................................. 97 17. The Request Handler Component .............................................................. 100 17.1. Introduction .................................................................................................... 100 17.2. Getting Client/Request Information .................................................................. 100 17.3. Stripping Data ................................................................................................ 103 17.4. Other Useful Functions ................................................................................... 103 18. The Security Component ........................................................................... 105 18.1. Introduction .................................................................................................... 105 v</p> <p>CakePHP</p> <p>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 ? ...............</p>