Over the last year or so, NCM has begun utilizing a tool called CakePHP to build some of its websites. CakePHP is a PHP-based flexible framework which allows developers to quickly build web applications in a manner similar to Ruby on Rails. It has a large, very active community and is based on free, open source projects. Because of this, support for the framework is widely available and easy to come by, both via the web, IRC, or local and web-based user groups.
Sites built with CakePHP follow what is known as the Model-View-Controller paradigm, sometimes known simply as MVC. Developing using the MVC paradigm makes CakePHP an excellent tool that developers can use to solve problems by breaking the functionality down into discrete, logical chunks.
The first of these layers, the model, only deals with the data and how it is structured and related. The view layer contains the scripts that only concern themselves with the portions of the application that people see in their browsers (it's sometimes known as presentation layer). The controller is the layer that glues the model and the view layers together – it consists of the business logic that is run when communication between model and view occurs. Code in the controller is run after a user has submitted information to the website, or after data has been fetched from the database and before it is displayed to the user.
When a change needs to be made to a CakePHP-based project, depending on what layer it will affect, it will be developed within one of these layers. This separation of layers of functionality allows us to develop quickly by letting multiple developers work simultaneously on the parts of the site at which they are most proficient. Production can develop beautiful front-end interfaces by working within the scripts that are at the view level, while at the same time programmers can be adding new functionality to the application at the controller level. Data issues, such as defining the relationships between tables and implementing validation can be separately addressed in the model by those with the most expertise at data modeling.
When should you develop a site using CakePHP instead of another tool? There are several situations in which it shines. The larger, more customized, and more data-intensive a project is, the more CakePHP makes sense as the solution. Cake keeps things organized by emphasizing convention over configuration. This means that when you set up a CakePHP project, you need to follow a few rules in order for everything else to fall into place. These rules dictate several things: they describe a naming convention for your database tables and fields, they lay out a specific directory structure for organizing your code, and they enforce an object oriented class-based structure for your code implementation.
While this initial setup may sound as though it means more work, it is actually a very forward thinking way of going about developing a project. Because everything is structured in a well-defined manner, you are safe to make assumptions about where things will be and how they will work. This standardization makes the whole framework much more extensibile and easy to develop for. In the same way that the RSS standard has made it easy to publish your own data and read in other peoples' data, CakePHP's agreed-upon structure makes it easier for developers to extend its basic functionality, letting you get to the finish line of your project faster than if you were coding everything by hand.
Additionally, the more developers will be working on a project at once, the more it makes sense to develop the product in CakePHP. As described earlier, due to it's MVC structure – various types of developers can be working in unison on a project, without stepping on each others' toes. Pairing this with a good version control system like SVN (we use Beanstalk) makes this even easier.
Finally, the more customized the requirements are, the more it makes sense to use CakePHP. By leveraging the CakePHP framework, you automatically have at your fingertips an arsenal of core functions (based on classes called Helpers) that can be used for anything from querying the database in a safe manner, generating standards-compliant HTML for front-end components, and building your own custom plugins which let you leverage already existing tools to extend the capabilities of your web application. You can even write your own helpers if you need additional functionality, or use some that have been written by the community. Due to the agreed-upon structure of CakePHP, you can easily build new functionality into your applications.
While CakePHP can be used to build a wide variety of applications, there are some types of projects for which CakePHP is not necessarily the best tool. CakePHP is most likely overkill for web-enabling very small or simple data sets, and definitely so for building static websites. Each time it runs, it loads a number of libraries which establish communication to and from the database, and to enable the MVC layers. If your site does not use this functionality, it would have a smaller footprint if you did not use CakePHP.
CakePHP would also not be appropriate if there is another tool that already exists that does the same thing. For instance, it would not make sense to use CakePHP to implement a blog if Wordpress will address your needs, since Wordpress is a mature and very successful application that focuses on blogging. If you require a CMS with multiple layers of authoring and approval, a site driven by the Drupal CMS would probably be a better solution than cobbling a system out of CakePHP. While you could implement these types of systems in CakePHP, to do so would be akin to reinventing the wheel – it'd be much more cost efficient to go with a product that does this already.
If you are interested in learning more about the CakePHP framework, check out the community website over at www.cakephp.org.




I have just hired a programmer full-time to build a site in PHP. He is using CakePHP. Let’s say it ends up being another ‘facebook’. Do I own any of the code or can anyone legally rip-off our site because it is open source? I tried to understand the MIT, GPL left right licenses, whatever thing but am obviously not smart enough to understand what anyone is talking about?
Can you tell me whether I own the final code to my site or does using CakePHP mean I do not? Thanks Gary Strial
——-
Posted by Gary Strial on 05/15/09 at 12:35PM