As I mentioned the other day I’m trying to work a new project in CakePHP which is the first time I’m working in the PHP framework. Actually I haven’t even really gotten into working with on the project yet - just working my way through some Cake tutorials. Even though it’s early in the process I thought I’d share some initial impressions.
Cake Forces Good Habits
One of the knocks against PHP in general is that it’s easy (and common) to mix your business logic, database access and display all together in one big mishmash. That’s certainly a valid complaint and I’ve done plenty of scripts that work that way but to be honest I don’t think that’s a terrible thing for a small project. Part of what motivated me to try Cake was the fact that Cake development follows the MVC (model-view-controller) pattern which separates the three parts into their own little area. I suppose it’s not entirely true that Cake forces this - you can certainly put all the PHP code you want into your template files - it would be crazy to try to use Cake without embracing MVC.
Cake Forces Domain Thinking

photo credit: DetroitDerekIt’s easy as a programmer to start thinking in terms of code and database tables. “The blog table has a userid that’s a foreign key to the users table”. Since Cake handles the database actions for you, you need to think in domain terms and define those relationships in your Cake models - a blog belongsTo a user; a user hasMany blogs. I think this is good but requires a bit of a change in how you approach the task at hand.
Cake Makes Some Stuff Very Easy
If you want a website that allows you to add, edit and delete entries in a simple database table you can do it all in minutes with Cake. Maybe even quicker. Unfortunately while that can get development up and going quickly that’s not useful in the real world. First, few useful applications are simply working with one database table. Second that quickie app doesn’t include user authentication. Third that generated app likely doesn’t look much like something you’d want in production. You can do all that - work with more complex databases, add user authentication, change the look - but its not going to be done in minutes.
Some of the cake tutorials and materials will point out that “You just accomplished [something amazing] with just 3 lines of code!”. That’s great and you can do some very cool and complex things with Cake with very little code but keep in mind that the code is often not the easiest thing to come up with in the first place.
Cake Uses Tons of Conventions
Part of how Cake accomplishes so much with so little code is by using conventions. Your database table is named “users” - all lowercase and plural and contains a field named “id”. Your model is in a file named “user.php” - singular and contains a class named “User”. Your controller is in a file called “users_controller.php” and contains a class named “UsersController”. You’re not technically required to follow all those naming conventions but doing so is part of what makes things “just work” in Cake.
Tons of Anonymous Arrays
Lots of parameters are passed as arrays which lead to lots of code that looks like this:
$this->redirect(array(’action’ => ‘index’), null, true);
As a gift to your favorite Cake developer you can find a key board that has a single key that will generate the word “array”. It’s a minor thing and I suspect something you quickly get used to.
Is It Worth It?

photo credit: geishaboy500I still have a long way to go to being productive with CakePHP but so far I think it’ll be worth the effort. Partially because of the promise that once you get proficient, development will get very fast. Partially because Cake handles the grunt work very well letting you focus on the business logic and domain work. Partially because it’s just fun to be working with some new and fairly advanced technology.
In general I learn best by just digging in and doing stuff and I think that’s the next step for me with Cake. I’ll update in the future with how it goes from here.
2 comments ↓
As mi first experience too, I am trying prado. Until now I am reading some prado tutorials. Maybe we can share the cons and pros of each one.
I’d be interested in hearing your impressions of Prado. It’s going to be hard to compare Cake and Prado since they both use very different paradigms. I’m pretty familiar with the MVC pattern but haven’t really worked within the component/event model.
Leave a Comment