June 13th, 2007
Early Impressions of CakePHP
This certainly isn’t a comprehensive review of CakePHP. I have a client that wants to use CakePHP so they can support it internally. I’ve just barely scratched the surface, but the whole point of Cake is to allow you to develop something useful on a very short learning curve. Since it is freely available, I thought I’d share my first outing with this rapid development framework for anyone on the fence about giving it a shot.
My first suggestion: unless you are an uber geek, don’t start with the official manual. It can be a little overwhelming. There are a lot of CakePHP tutorials available through Google. Once you’ve gone through one or two of those, the manual will be a much easier read.
And you should read it because it is packed with some great information and examples. I just didn’t understand most of them the first time through. The biggest problem is that the manual doesn’t stick with a single data structure throughout. Sometimes examples are with Users, other times with Posts, and still other times Leaders… and I’m only talking about a single HTML page. I realize the writers do this so they can pick examples that best explain the aspect of CakePHP being described at that point. Just realize that the manual isn’t written for the completely uninitiated.
You’ll find features that you would expect in any decent code framework, such as a file where you can define global variables and functions. But CakePHP has something that I haven’t seen before (at least in my experience with PHP frameworks). You define the relationships between database tables in the code. The syntax takes some getting used to, but once you do this step is very quick and easy.
The advantage is that you never have to write an SQL query (although you still can). Build an HTML form that will save data to multiple tables. If you’ve defined the relationships (and named the form inputs correctly), it only takes one line to save all of the form data to the appropriate tables in the database.
The secret to the success of CakePHP is the strict adherence to naming conventions. If you want to take advantage of some of the built in short cuts, you need to use variable names, table names, and even column names (for primary and foreign keys) that match what CakePHP is expecting. The good news is the specifications are pretty straightforward. Once you know what is expected, it’s easy to write your code in accordance.
Of course this means there’s probably not going to be many cases where it makes sense to convert an existing web site to CakePHP. All the strengths of CakePHP are focused on allowing you to create brand new web sites rapidly.
I know I’ll still be learning more in the next few weeks. I’ve seen several tantalizing references to the ability to “bake” and application. The little I’ve read seems to hint that you can construct a database, and the bake function will automatically create a skeleton of the code that will eventually become your web site. Now that is a killer feature. Any readers want to share their first experiences with CakePHP?




Jun 25th, 2007
11:58 am
So you’re enjoying your cakephp experience
If you check out the 1.2 source there’s a lot of killer new features like access control lists, and hopefully the return of data models as objects instead of associative arrays (this hasn’t been implemented yet).
Bake is pretty cool. You can define you database according to the conventions defined in the manual and bake your applications with scaffolding and add things like admin routing and such to get a skeleton of the app. It’s bittersweet though. You’ll tend to think you can use scaffolding in your production applications, but it’s not very good practice.
http://cakephp.org/screencasts/view/1 - a screencast demonstrating the way bake is used.
It’s easy enough to convert existing apps to cake as well. It’s possible to override the primary key and how relationships are defined by setting the model data appropriately. Nice article though!
Jun 26th, 2007
8:32 am
I have played around a little with bake now. It’s impressive that they came up with such a comprehensive script to handle all the possible data associations. I must be one of the few people that isn’t at all tempted to use it for a production environment, though. (The automatic input forms treat foreign keys as a select box with all the possible values of the foreign key, instead of a meaningful label? There’s just too many things like that.) I anticipate I will use bake to create the model and control framework of my applications, but I probably won’t even bother with creating the scaffolding views.
Thanks for putting me onto this framework, though, Kris.
Jul 5th, 2007
9:12 am
Scaffolding isn’t really for production environments. It’s just a place to start from.
I don’t know if you’re familiar with test-driven development or not, but you might be interested in http://simpletest.sourceforge.net
It’s a development approach where defining the application behavior (with a test) comes before writing the actual behavior itself. http://behaviour-driven.org/ (this site is geared toward rails developers, but it applies)
It seems like changing the development style would only complicate things for myself and my clients, but I’ve found that by using test driven development I have less problems at crunch-time..