CakePHP 1.3 Manual
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
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.
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
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
Back to top
1.2. Where to Get Help 220.127.116.11.http://www.cakephp.org
# The Official CakePHP website
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.
# 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.
# 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.
# 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.
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.
# 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.
# The IRC channel
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.
# 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.
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.
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