I have always been on the lookout for a lightweight framework that I could use for different projects. Using PHP for the majority of my projects, I looked into CakePHP, Zend Framework, Code Igniter, and Symfony. Now, to be fair, I did not learn each of these to their full potential. One of the deciding factors to me was how easy it was to get setup and running. I had looked at these around 8 months ago, but a recent discussion with Nathan Smith inspired me to check them out again. I downloaded each of the packages and set them up on my server — simply to take a look at their code, support, and documentation. I found CakePHP to be the easiest to get up and running (not that the others were hard). I found Zend to offer much of what I was looking for at its core (clean OOP code, PHP5, nice feature set) — but getting up and running was not a simple task.

CakePHP makes this a breeze by literally walking you through the steps. It lets you know if it can connect to your database, write to your /tmp folder, and then progressively lets you know if you are missing a controller, model, or view. If you were missing any of the following — it lets you know exactly what you needed to do to solve the problem (this is with the default debug set to 2). I was familiar with the CakePHP structure — and preferred it to some of the others in it’s flexibility. The directory structure is very straightforward, but allowed me to move pieces as I needed. For instance: I wanted the core cake folder to exist at the root of our server, so I could share it with several CakePHP apps. This was a breeze to implement, and helps with future updates and upgrades. One thing I liked about Cake versus Zend was how it handled things automagically — versus always having to hit the registry to retrieve and initialize an object, array, or variable. Last week I ported a previous website, primarily database driven, to a Cake application to hand over to a client. I must say, I enjoyed my time doing this. Here are a few other things I have noted about Cake:

  • When I checked out Cake 8 months ago, I felt like I was locked into their naming conventions in regards to database structure. This was a big turn off due to an already existing database structure. I like the way the models are setup, and creating relationships is easy (hasone, hasmany, belongsto, and hasandbelongstomany). Once the model is setup, creating forms and running the validation (you can specify built in rules or regex) is a breeze. This was key for rapid development.

  • A Very small config file and you are instantly setup and running. With just a few config options, you can handle things like ACL, sessions, security, output, and debugging. This was an advantage, because I didn’t want to really have to spend time configuring something before I could use it.

  • Limited need for mod_rewrite. You could use the Apache’s lookback functionality to have URL’s like index.php/controller/action/params/ if you didn’t have mod_rewrite. I was initially worried about this because I like to use mod_rewrite for custom routing and mapping multiple URL’s to one base. I was very pleased to see the easy implementation of custom routing inside of Cake. When I recently ported an application to Cake, I wanted to keep the existing URL’s — and I was able to do this without a problem thanks to the custom routing. The only issue (and this is minor to some) was that the custom routing doesn’t work exactly like it would with mod_rewrite. For instance, I like to make sure all URL’s have one point of entry. So http://www.domain.com/page/ would be the main page, and if someone type in http://www.domain.com/page it would redirect them to the previous page). Doing this helps keep things neat and tidy in logs and in analytics and reporting. Having pages available at both page and page/ results in 2 different pages to logs and search engines.

  • Having the option to override the core, without touching the cake core. I initially had a little block, but was quickly guided by Jonathan Snook on how to achieve the task. I felt stupid at how easy the answer to my question was. The ability to extend the app_controller, app_model, app_helper was a very nice aspect. Also, having the ability to create custom tags with an INI file was very nice. This made it easy to create custom helpers. My only complaint with using the default helpers is the doctype. I wish that you could declare a doctype for your page (HTML/XHTML) via the HTML helper, and then the rest of the helpers would build their tags in line with the current doctype. (If this is possible and I am not aware — please point me in the right direction).

  • Handling of sessions and caching was a breeze. Granted, it is only view caching — it is still a nice option. One of the config options is to set how to handle sessions (PHP, Cake, or Database) — and again, a very nice feature to manage sessions.

These are just a few reasons why I really like the CakePHP Framework — and it is not to say that some of these might not be available in the other frameworks. I just happened to stick with CakePHP due to it’s ease of setup and documentation (API). Though documentation could be greatly improved, it was rare that I hit a problem that couldn’t easily be fixed. I like the code, I like the documentation, and I like the community (I can’t leave out Felix — who has a vast amount of resources on his site).

A small disclaimer: I have used the RoR framework and absolutely love it. This is partly why I chose to use Cake due to many of its similarities. I haven’t migrated to RoR for several reasons:

  1. I am not, admittedly, fluent in Ruby — and I like to know what is going on at the core so I can fix or modify things if necessary.

  2. I recently moved to a server that supports RoR, but other servers I have worked on do not have RoR available.

  3. I like to completely know what I am doing before I jump into something. I have read several Rails books — but I like to know the inner workings and the language. Yes, there is always Stephen to help me out and point me in the right direction (and to tell me why PHP sucks) — but this is something I need to learn personally before I begin using it on a larger scale.

13 Comments Add your comment

  1. Jina Bolton February 8th, 2007

    How come you're not using RoR?

    Just kidding, I read the disclaimer. :D

  2. Nate Klaiber February 8th, 2007

    Jina Jina Jina....It sounds like you are forming an alliance with Stephen to convert me. hehe. In all reality, having Stephen there to help me has made rails all the more fun when I play with it and really learn (the right way). I just need to learn more.....

    In other news, how can we have a Gus's web conference if you are up and leaving? You gonna fly us to Cupertino? :)

  3. Sam McDonald February 8th, 2007

    Sounds good. I am currently learning Code Igniter for my current projects, and really like it. The main thing I like, is when I think things like, "Hey I should write something that handles this." I check Code Igniter's user guide and realize it has already been programmed.

  4. Nate Klaiber February 8th, 2007

    Sam, I have found the same thing to be true with Cake. Personally, I like the code structure/organization better in Cake than in CodeIgniter. CI is very similar in many aspects, I just feel like Cake is more mature (And seems to be getting better). However, I still think CI is a very nice framework to use - and it does a great job of abstracting some of the mundane tasks.

    I hope that the documentation gets a little better for Cake. There are some things in their 'Manual' that differ slightly from their API. I have found the best way to find which one is right is to look at my current version and the code. It is very well commented (And keeps up to date with letting you know about deprecated functions and the like).

  5. Chris Hattery February 16th, 2007

    Mmm. Cake

  6. Igor March 20th, 2007

    Why don't you give PHPonTrax try. It's really nice PHP-framework, that much more near to RoR as CakePHP.

  7. Nate Klaiber March 20th, 2007

    RE: Igor
    I had taken a brief look at PHPonTrax, but I have really jumped in with CakePHP. With the available array of frameworks out there, I had to find one that would work for me - then spend time to learn the framework itself. CakePHP is working wonders for me, but that doesn't mean its better than PHPonTrax - just a personal preference.

    Have you used it? Or are you using Rails?

  8. Wilman July 11th, 2007

    I liked cakephp. I also checked and read all RoR books (suggested in RoR website) and had the same feeling.
    I feel tempted to go to RoR but I have not done it for the same reasons you pointed out.

    However, I found pretty attractive a few features about RoR (true ORM, true OOP and test environment).
    Anyway, I will try to use cakephp in my next project and see how it goes.

    Thanks for your comments :)

  9. Nate Klaiber July 11th, 2007

    @Wilman
    With my new job I have started working in RoR. I have enjoyed my time doing so, but I am very specific about knowing the underpinnings - so I have spent some time in some Ruby books as well.

    Those features of RoR are wonderful. Mainly, the true OOP is incredible. The ORM is wonderful, with full flexibility to extend at any point in your application. I try to keep fat models and thin controllers, and I love the simplicity of extending ActiveRecord for some of their automagic stuff.

    I would be interested to hear your feedback and experience with CakePHP - it is an awesome framework!

  10. Almanca tercüman January 16th, 2008

    I am currently learning Code Igniter for my current projects, and really like it. The main thing I like, is when I think things like, Hey I should write something that handles this..

  11. Paul (3-bids) January 22nd, 2008

    @Nate, a couple of questions. If you had to do a fairly large project with a lot of database interaction, would you use Cake or RoR? Have you ever looked into Drupal?

    Thanks,
    Paul

  12. Nate Klaiber January 23rd, 2008

    @Paul
    I would most likely use RoR at this point. Rails gives you a great deal of flexibility to optimize your queries no matter how you use them (association proxies, straight queries, etc). So it would really come down to the preference of language, which for me is now Ruby (has changed since this original article).

    However, that doesn't mean you should count out CakePHP.

    I have looked into Drupal and I don't like it. Too much overhead right from the get go. I like working with a clean slate and building in just the things I need.

    Hope this helps.

  13. cowfish March 2nd, 2008

    @Nate

    What is meant by "true OOP"? What's the difference between CakePHP's implementation of OOP concepts and RoR's?

Leave a comment

Basic HTML is allowed (a href, strong, em, blockquote).