CakePHP 1.3 Manual

download CakePHP 1.3 Manual

of 484

  • date post

    28-Nov-2014
  • Category

    Documents

  • view

    1.628
  • download

    3

Embed Size (px)

Transcript of CakePHP 1.3 Manual

The Manual1. 1.1. 1.2. 1.3. 2. 2.1. 2.2. 2.3. 2.4. 3. 3.1. 3.2. 3.3. 3.4. 3.5. 3.6. 3.7. 3.8. 3.9. Beginning With CakePHP What is CakePHP? Why Use it? Where to Get Help Understanding Model-View-Controller Basic Principles of CakePHP CakePHP Structure A Typical CakePHP Request CakePHP Folder Structure CakePHP Conventions Developing with CakePHP Requirements Installation Preparation Installation Configuration Controllers Components Models Behaviors DataSources 5 5 5 7 8 8 10 11 12 15 15 15 16 25 42 57 62 133 138

3.10. 3.11. 3.12. 3.13. 3.14. 3.15. 3.16. 4. 4.1. 4.2. 4.3. 4.4. 4.5. 4.6. 4.7. 4.8. 4.9. 4.10. 5. 5.1. 5.2. 5.3. 5.4. 5.5. 5.6.

Views Helpers Scaffolding The CakePHP Console Plugins Global Constants and Functions Vendor packages

142 151 156 158 163 168 174 174 174 191 193 195 197 198 200 220 223 229 232 233 246 261 263 268 273

Common Tasks With CakePHP Data Validation Data Sanitization Error Handling Debugging Caching Logging Testing Internationalization & Localization Pagination REST

Core Components Access Control Lists Authentication Cookies Email Request Handling Security Component

2

Back to top

5.7. 6. 6.1. 6.2. 6.3. 6.4. 7. 7.1. 7.2. 7.3. 7.4. 7.5. 7.6. 7.7. 7.8. 7.9. 7.10. 7.11. 7.12. 7.13. 8. 8.1. 8.2. 8.3. 8.4.

Sessions Core Behaviors ACL Containable Translate Tree Core Helpers AJAX Cache Form HTML Js Javascript Number Paginator RSS Session Text Time XML

278 281 282 283 289 295 308 308 320 323 349 361 374 377 380 381 385 387 389 392 394 394 395 396 397

Core Utility Libraries App Inflector String Xml

3

Back to top

8.5. 8.6. 8.7. 8.8. 9. 9.1. 9.2. 9.3. 10. 11.

Set Security Cache HttpSocket Core Console Applications Code Generation with Bake Schema management and migrations Modify default HTML produced by "baked" templates Deployment Tutorials & Examples Blog Simple Acl controlled Application

398 427 428 430 431 432 434 436 436 436 437 451 464 464 475

11.1. 11.2. 12.

Appendices Migrating from CakePHP 1.2 to 1.3 New features in CakePHP 1.3

12.1. 12.2.

4

Back to top

1. Beginning With CakePHPWelcome to the Cookbook, the manual for the CakePHP web application framework that makes developing a piece of cake! This manual assumes that you have a general understanding of PHP and a basic understanding of object-oriented programming (OOP). Different functionality within the framework makes use of different technologies such as SQL, JavaScript, and XML and this manual does not attempt to explain those technologies, only how they are used in context.

1.1. What is CakePHP? Why Use it?CakePHP is a free, open-source, rapid development framework for PHP. Its a foundational structure for programmers to create web applications. Our primary goal is to enable you to work in a structured and rapid mannerwithout loss of flexibility. CakePHP takes the monotony out of web development. We provide you with all the tools you need to get started coding what you really need to get done: the logic specific to your application. Instead of reinventing the wheel every time you sit down to a new project, check out a copy of CakePHP and get started with the real guts of your application. CakePHP has an active developer team and community, bringing great value to the project. In addition to keeping you from wheel-reinventing, using CakePHP means your applications core is well tested and is being constantly improved. Heres a quick list of features youll enjoy when using CakePHP: Active, friendly community Flexible licensing Compatible with versions 4 and 5 of PHP Integrated CRUD for database interaction Application scaffolding Code generation MVC architecture Request dispatcher with clean, custom URLs and routes Built-in validation Fast and flexible templating (PHP syntax, with helpers) View Helpers for AJAX, JavaScript, HTML Forms and more Email, Cookie, Security, Session, and Request Handling Components Flexible ACL Data Sanitization Flexible Caching Localization Works from any web site directory, with little to no Apache configuration involved

1.2. Where to Get Help 1.2.1.1.http://www.cakephp.org

# The Official CakePHP website

5

Back to top

The Official CakePHP website is always a great place to visit. It features links to oft-used developer tools, screencasts, donation opportunities, and downloads.

1.2.1.2.http://book.cakephp.org

# The Cookbook

This manual should probably be the first place you go to get answers. As with many other open source projects, we get new folks regularly. Try your best to answer your questions on your own first. Answers may come slower, but will remain longer and you'll also be lightening our support load. Both the manual and the API have an online component.

1.2.1.3.http://bakery.cakephp.org

# The Bakery

The CakePHP Bakery is a clearing house for all things CakePHP. Check it out for tutorials, case studies, and code examples. Once youre acquainted with CakePHP, log on and share your knowledge with the community and gain instant fame and fortune.

1.2.1.4.http://api.cakephp.org/

# The API

Straight to the point and straight from the core developers, the CakePHP API (Application Programming Interface) is the most comprehensive documentation around for all the nitty gritty details of the internal workings of the framework. Its a straight forward code reference, so bring your propeller hat.

1.2.1.5.http://www.cakeforge.org

# CakeForge

CakeForge is another developer resource you can use to host your CakePHP projects to share with others. If youre looking for (or want to share) a killer component or a praiseworthy plugin, check out CakeForge.

1.2.1.6.http://api.cakephp.org/tests

# The Test Cases

If you ever feel the information provided in the API is not sufficient, check out the code of the test cases provided with CakePHP 1.3. They can serve as practical examples for function and data member usage for a class. To get the core test cases you need to download or checkout 1.3 branch from a git repository. The test cases will be located under1.

cake/tests/cases

1.2.1.7.

# The IRC channel

6

Back to top

IRC Channels on irc.freenode.net:

#cakephp -- General Discussion #cakephp-docs -- Documentation #cakephp-bakery -- Bakery

If youre stumped, give us a holler in the CakePHP IRC channel. Someone from the development team is usually there, especially during the daylight hours for North and South America users. Wed love to hear from you, whether you need some help, want to find users in your area, or would like to donate your brand new sports car.

1.2.1.8.

# The Google Group

http://groups.google.com/group/cake-php CakePHP also has a very active Google Group. It can be a great resource for finding archived answers, frequently asked questions, and getting answers to immediate problems.

1.3. Understanding Model-View-ControllerCakePHP follows the MVC software design pattern. Programming using MVC separates your application into three main parts: 1. The Model represents the application data 2. The View renders a presentation of model data 3. The Controller handles and routes requests made by the client

Figure: 1: A Basic MVC Request Figure: 1 shows an example of a bare-bones MVC request in CakePHP. To illustrate, assume a client named "Ricardo" just clicked on the Buy A Custom Cake Now! link on your applications home page.

Ricardo clicks the link pointing to http://www.example.com/cakes/buy, and his browser makes a request to your web server. The dispatcher checks the request URL (/cakes/buy), and hands the request to the correct controller. The controller performs application specific logic. For example, it may check to see if Ricardo has logged in.

7

Back to top

The controller also uses models to gain access to the applications data. Models usually represent database tables, but they could also represent LDAP entries, RSS feeds, or files on the system. In this example, the controller uses a model to fetch Ricardos last

purchases from the database. Once the controller has worked its magic on the data, it hands it to a view. The view takes this data and gets it ready for presentation to the client. Views in CakePHP are usually in HTML format, but a view could just as easily be a PDF, XML document, or JSON object

depending on your needs. Once the view has used the data from the controller to build a fully rendered view, the content of that view is returned to Ricardos browser.

Almost every request to your application will follow this basic pattern. We'll add some details later on which are specific to CakePHP, so keep this in mind as we proceed.

1.3.1.1.

# Benefits

Why use MVC? Because it is a tried and true software design pattern that turns an application into a maintainable, modular, rapidly developed package. Crafting application tasks into separate models, views, and controllers makes your application very light on its feet. New features are easily added, and new faces on old features are a snap. The modular and separate design also allows developers and designers to work simultaneously, including the ability to rapidly prototype. Separation also allows developers to make changes in one part of the application without affecting others. If you've never built an application this way, it takes some time getting used to, but we're confident that once you've built your first application using CakePHP, you won't want to do it any other way.

2. Basic Principles of CakePHPThe CakePHP framework provides a robust base for your application. It can handle every aspect, from th