CakePHP Applications Development

CakePHP Applications Development

Learning the CakePHP 1.2 Framework Through Examples.

What is Cake?
Along with others like Zend’s framework, Symfony and CodeIgniter, CakePHP is one of the most popular PHP frameworks around today. Initially inspired by Ruby on Rails, it incorporates several features that can speed up application development. This includes code generation, “convention over configuration” (i.e. it expects placement of files and names to follow specific rules) and common design patterns like MVC and ActiveRecord that can help keep your code maintainable. It’s this ease of development that has made it popular.

Cake, like ‘Rails, is also an example of a “full-stack” framework, as opposed to “component frameworks” like Zend’s. The easiest way to think of the difference between these two kinds is: with Cake (or Symfony, another full-stack framework) you are most productive when you understand where the framework expects to find things and what it expects them to be called. If you follow these conventions, you’ll discover CakePHP takes care of a lot of details for you. The catch is you generally have to buy into the whole framework– you can’t pick what parts of your project will use the framework and what won’t– though Cake will allow you to incorporate libraries that don’t use its structure. As well, there is a bit of a steeper learning curve as you have to understand how the whole thing fits together.

On the other hand, component frameworks give the developer more choice about what parts of the framework to use as these frameworks are designed to be used in pieces. But the trade-off is you tend to have to configure and specify things more as a component framework can’t make the same assumptions about how things are organized because they are designed so the parts can be used individually. So full-stack frameworks might let you build applications quicker, but you have to do things their way, while component frameworks allow you choose what will be handled by the framework, but put more of the burden of setting things up on the developer.

See also  Build Mobile Websites and Apps for Smart Devices

Learning the rules of the Cake framework has been a challenge in the past, both because of inadequate or out-dated documentation. Though the official documentation has improved immensely in the last year, it doesn’t aim to teach Cake to complete beginners. Packt’s book is one of two English-language books released this summer covering the CakePHP framework (the other being Apress’ Beginning CakePHP ).

Packt’s CakePHP Applications Development does take the reader through all the steps right from downloading Cake and installing it on a server running either Windows or Linux. The server documentation isn’t that detailed — I hoped they’d show how to set up multiple projects using virtual directories or similar–, but it should get people started. After an introduction to the under-laying MVC pattern that Cake uses, the book then takes the reader through setting up Cake and creating a simple database-driven application, CakeToDo. The next four chapters cover Cake’s implementation of controllers, models and views. Later chapters build a complete application, QuickWall, that incorporates a lot more of Cake’s features including user log-in with the Auth and Email components. Near the end of the book, Ajax and generating RSS feeds is covered too. In general, what it does cover is pretty good. There are plenty of “What just happened?” sections that explain in some detail what a particular block of code is doing. As well, there is a lot of tips that, like how to create a controller without a model or watching out for “<?php … ?> ” (trailing spaces) in models/controllers that can cause hard to find errors (Zend Framework’s guidelines suggest leaving off the closing PHP tag for this reason). This book will give readers new to Cake a solid foundation for writing applications.

See also  Map Scripting 101

What doesn’t this book teach?
Unfortunately, CakePHP 1.2 is still evolving even at the time this review is being written. While you can’t fault the authors, there are a few things that have changed, for instance, the often-usedgenerateList() has been deprecated, and the SQL operators have switched places (e.g. ” ‘User.name !=’ => ‘Joe’ ” instead of ” ‘User.name’ => ‘!= Joe’ ) when specifying model find conditions are two changes that come to mind. As well, there is no coverage of the very useful Containable Behaviours as an alternative to adding/removing bindings (which showed up probably after the book was written). Speaking of “behaviours”, there is no coverage of them in the Model chapters. Some components are covered like Auth, Email, but other like ACL or the handy Set core component aren’t. Neither is there much coverage of security, but in that regard, Cake Applications isn’t alone– many beginner books overlook that aspect.

Way of the Cake
Finally, a few of the reviews have mentioned that there isn’t much coverage of doing things “The Cake Way”, or how to decide how to solve a problem in a way that fits in with the framework logically. To honest, this is kind of a step beyond beginner and its something that shows up in blogs and posts to the Google Group mailing list frequently. I think as long as coders keep a few rules in mind, like trying to keep as much logic out of the View end of MVC and don’t go changing the files in the /cake directory, then it’s probably OK.

See also  The Art of Scalability

Closing
I started frameworks using Symfony a few years ago and just learning how things were organized a significant hurdle. Cake, I believe, has a more straightforward structure, and does a lot of hand-holding for developers. Other reviews of the book have pointed out that there are a few flaws with this slim 300-page book: primarily some out-of-date information, no coverage of the testing framework, localization or writing shell scripts, and doing things “the Cake way”. I tried to approach this book as to how useful it would be to someone unfamiliar with the CakePHP, and I think it’s a fair job. If Packt releases an updated version once the final 1.2 arrives, it would be an excellent choice for new users, as it stands, it’s still recommended with an asterisk.