Beginning With CakePHP
Patty-cake, patty-cake...
Preface
Welcome to web development heaven.
If you’re reading the preface to a technical manual, you probably have too much time on your hands. We’re not celebrities, and since the material is what you're after, skip this superfluous section and dive right in.
1 - Is Preface "Superfluous?"
I might not position the first message the reader as, "Don't read this." What does everyone think of this instead:
Welcome to web development heaven!
CakePHP let's developers develop, designers design, and users use your masterpiece. Developers have literally dozens of PHP web application frameworks to choose from currently. CakePHP stands alone because it doesn't rely on multiple 3rd party frameworks to support core functionality, has a clear development support timeline, and has broad industry support from large scale projects.
You've come to the right place! A lot has changed since CakePHP 1.1 and we're excited to get you started learning CakePHP 1.2.
2 - err...
not "let's" just "lets" Missed that one in the proof.
Audience
This material is written for developers at all levels of ability; anyone who enjoys creating robust, maintainable applications quickly and effectively.
In order to understand the content of this document, you're going to need to have a working knowledge of PHP. Some basic familiarity with object-oriented programming will also help, though I suppose the introductory sections of this document could act as a primer of sorts.
There will be content that addresses technology which is technically beyond the scope of this document and not specific to the CakePHP framework. Some of these technologies include:
- AJAX
- JavaScript
- SQL
- Web Server Administration
Introduction to CakePHP
1 - History
What happened to the history that's in the 1.1 manual? I'd like to know what came before cake, who baked it and why.
What is CakePHP? Why Use it?
CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. Our primary goal is to enable you to work in a structured and rapid manner–without 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 application’s core is well tested and is being constantly improved.
Here’s a quick list of features you’ll 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
Where to Get Help
The Cookbook
You've started in the right place. 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 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.
The IRC channel
#cakephp @ irc.freenode.net
If you’re 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. We’d 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 Bakery
The CakePHP Bakery is a clearing house for all things CakePHP. Check it out for tutorials, case studies, and code examples. Once you’re acquainted with CakePHP, log on and share your knowledge with the community and gain instant fame and fortune.
CakeForge
CakeForge is another developer resource you can use to host your CakePHP projects to share with others. If you’re looking for (or want to share) a killer component or a praiseworthy plugin, check out CakeForge.
The Official CakePHP website
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 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.
Understanding Model-View-Controller
Overview
CakePHP follows the MVC software design pattern. Programming using MVC separates your application into three main parts:
- The Model represents the application data
- The View renders a presentation of model data
- 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 application’s 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.
- The controller also uses models to gain access to the application’s 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 Ricardo’s 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 Ricardo’s 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 - Graphic missing
There seems to be a graphic from tempdocs missing. How do you enter graphics into the cookbook?
2 - duplicate content
This part is also described in:
http://book.cakephp.org/view/21/a-typical-cakephp-request
although they differ a bit, i think one of them can be removed
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 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.

By pr1001 1 day, 17 hours ago
1 - Wrong Location
Why is the introduction to the entire manual part of the Sessions chapter?
login to add a comment