Research Article
Introduction
“Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.” So goes the mission of CakePHP. This essay will explore the history of the framework, some of the basic theory and functionality behind CakePHP, an example of CakePHP in the wild, and the vast and active community supporting the framework.
What is a framework?
“In computer programming,” states Wikipedia.org, “an application framework is a term usually used to refer to a set of libraries or classes that are used to implement the standard structure of an application.” On its website, CakePHP defines itself as a “free open-source rapid development framework for PHP. It is a structure of libraries, classes and run-time infrastructure for programmers creating web applications.”
History of the Cake
The development of CakePHP was inspired and heavily influenced by Ruby on Rails. RoR is an extremely popular web application framework extracted by David Heinemeier Hansson from the project management application he was working on Basecamp. Web developer Michal Tatarynowicz wanted a PHP equivalent to the powerful flexibility afforded by RoR, and in 2005, the first incarnation of CakePHP was released under the MIT license as Cake. It is now maintained by a very active community of developers under its current name.
MVC, yeah you know me
Similar to the web design best practice of keeping content separate from style, web development has, well, developed its own set of best practice standards. One of them is the Model-View-Controller. According to the CakePHP manual, MVC “is a software design pattern that helps you logically separate your code, make it more reusable, maintainable, and generally better.” It operates along the same principles as Object-Oriented Programming--essentially keeping code as flexible and recyclable as possible. MVC was first written about by Dean Helman in the white paper “Objective Toolkit Pro.”
The first part of the equation is the Model. In terms of CakePHP, the Model “represents a particular database table/record, and it's relationships to other tables and records” (CakePHP manual). It can also contain any data validation rules. The View is just like it sounds--it represents what the end-user views or sees. These View files are simply HTML files with PHP code sprinkled within them. The Controller represents the middleman, the traffic cop of the system. The controller handles the following:
- requests from the server
- takes user input (GET/URL and POST data)
- uses the Models to read, write, update data to and from databases
- finally, sends the output data to the appropriate View files
MVC requires strict adherence to naming conventions and directory structure. Consequently though, such strictness produces incredible flexible applications that can be reused and/or easily modified. One of the fastest ways to see this power and flexibility is through scaffolding.
Scaffolding
CakePHP provides “out of the box” support of scaffolding. Just as scaffolding helps a building be assembled more quickly, safely, and soundly, web application scaffolding allows a developer to quickly create a database-backed application. After the initial configuration of a database, the inclusion of a scaffolding variable (var $scaffold) can quickly construct the models and views of an application. (As a testament to this process, I created a blog-esque Content Management System in about ten minutes(!)).
The scaffolding around a building, however, detracts from some of the flexibility of the architect and the designer to truly show off the building and its appearance. The metaphor again holds true with CakePHP. Though it allows for the rapid development of an application, its more of a tool to help with setting up the structure. To truly be flexible with the abilities of the application, as well as the appearance of the views, the scaffolding has to come down eventually. But CakePHP still provides even further aids to rapidly create websites and web applications in the form of. . . 
Helpers
The CakePHP manual states that helpers “are meant to provide functions that are commonly needed in views to format and present data in useful ways.” These functions help take some of the monotony out of writing the same code over and over again. They aid in the quick creation of HTML elements, especially forms, as well as DOM scripting through support of JavaScript and AJAX (specifically the Scriptaculous and Prototype libraries).
Cake in the Wild (well, just Canada. . . )
While working on a new project in June 2006, web developer Jonathan Snook decided to look into this new framework he had been hearing about that was built entirely in PHP. Upon further exploration, he discovered the power and flexibility of CakePHP. By September of the same year, he had completely rebuilt his entire site in CakePHP: “CakePHP has given me the flexibility to drop in features quickly and easily.”
Everybody Loves Cake
CakePHP has a very active community. The “official” community site is The Bakery, which provides articles, tutorials, case studies, code snippets, and more. Another interesting community is the Cake Forge; the Forge describes itself as “free service provided to Open Source developers offering easy access to the best in mailing lists, bug tracking, message boards/forums, task management, site hosting, permanent file archival, full backups, and total web-based administration.” Cake Forge offers a subscription hosting service where developers can privately work on code and projects where their ideas are kept secret. There is also a CakePHP community on Google Groups with thousands of members and a “High activity” rating.
Conclusion
CakePHP is a powerful, flexible framework. By demanding developers adhere to strict naming and directory structure conventions, robust web applications can be rapidly built, modified, configured. Some of CakePHP’s useful features include:
- Model, View, Controller Architecture
- View Helpers for AJAX, Javascript, HTML Forms and more
- Built-in Validation
- Application Scaffolding
- Application and CRUD code generation
- Access Control Lists
- Data Sanitization
- Security, Session, and Request Handling Components
- Flexible View Caching
- And More...
To learn more about CakePHP, visit the Works Cited portion of this site. There you will find a list of links to groups and communities. Or, you may want to check out this online bookstore with great books on programming. If you’re a developer looking for a flexible framework with incredible potential and an amazingly active community, give Cake a try!

