Faceoff: CodeIgniter vs CakePHP

In the red corner, we have CakePHP, the heavyweight fighter with guns to show.
In the blue corner, we have CodeIgniter, the lightweight fighter, quick on the feet.

But seriously, I have worked a lot with these two frameworks and would like to compare and contrast them. I know this has been done many times but check it out from my eyes.

  • Round One: Introduction to the Frameworks
  • CodeIgniter is already throwing punches left and right while CakePHP is just warming up.

    From the first time you visit the respective websites, you will feel that CodeIgniter is better organized and more user friendly. Just as an aside, the CodeIgniter website is definitely a lot nicer looking than the CakePHP website. Both frameworks have their share of documentation and screencasts but CodeIgniter shines in how clear and thorough its documentation is. All the information you need to learn CakePHP is there. However, it takes a little more meddling around to find what you want, and for documentation on some of the helpers, you will need to go into the API and look at the code yourself to figure it out ocassionally.

  • Model View Controller Integration
  • CodeIgniter tries to pull off a combo but CakePHP blocks it and fires back with the same combo plus more.

    If you’re serious about MVC: use CakePHP. It’s that simple because the MVC design in CodeIgniter is just not developed. They probably have avoided this to keep the framework compact and in a sense, unnecessary (one of the “advantages” of CodeIgniter).

    First things first, there is no database abstraction in CodeIgniter. This means that models in CodeIgniter is more a concept than actual implementation. The models are there for you to implement yourself. CodeIgniter only prepares the separation of files. As for CakePHP, you can’t have an application without models. The models are tied directly to the database. This is where CakePHP shines. Each model you create corresponds to a table in the database. This model has built-in functions that work with the database. Put in another way, in CakePHP, your controllers work with your models, which automatically work with the database. With CodeIgniter, on the other hand, your controllers work with your models, which you code the queries to work with the database.

    To add even more WHAM, CakePHP supports model associations which, if used correctly, will make you never want to go back to older styles of programming again. In each CakePHP model, you can set variables which work as mappings between models. Think of that Visio diagram of your tables and how they associate with one another. For example, each post has several comments. The Post model would have a $hasMany variable pointed to Comment and the Comment would have a $belongsTo variable pointed at Post. Now, when you retrieve a Post through the Post model, you will also get all the Comments associated with that Post (and you can get the Post that a comment belongs to when you get a Comment). This is useful in most applications and will make your life a lot easier.

  • Community
  • Both fighters go back to their trainers and their respective fans cheer them on.

    The CakePHP and CodeIgniter communities have very different personalities. There are pros and cons to both so I’ll leave it for you to decide which one is better. First, the CakePHP community is a lot bigger than the CodeIgniter community. This is an advantage because you will find a lot more articles, buzz, and additional code for CakePHP. CakePHP has a Bakery which contains user-contributed tutorials, components, and other code snippets. With CakePHP, you’ll find heavy developers and generally more experienced programmers.

    The CodeIgniter community is a lot smaller and the best word to describe it would be underdog. The forums on the site are very active and you can expect to receive personal help rather quickly. The community recognizes the competitors and in a sense, you will join a band of brothers. There is definitely a stronger sense of community with CodeIgniter. The wiki is also useful but not as big as Bakery. However, one major downside to CodeIgniter, is that it is owned by a private company, unlike CakePHP. Therefore, bug fixes and enhancements take longer and are maintained by the company. Even though this might ensure some more quality, software that is contributed to by a community is bound to be developed faster and focused more on the needs of its users.

  • Which to use
  • To be fair, CakePHP and CodeIgniter serve different purposes so there is no clear winner to who is better. CodeIgniter acts as a helper while CakePHP serves as the core of your application. In general, CodeIgniter serves as a good way to structure your code. If you have a small application for which procedural programming will work, CodeIgniter does its job. In short, CodeIgniter is better than no framework.

    If you want to build a more complex application where a MVC design is necessary, then you will want to use CakePHP. The benefits of CakePHP lie in its use of convention to increase automation, which will really ease your development. If your application uses a relational database scheme, choosing which to use is a no-brainer. The amount of features and addons to CakePHP is also a lot bigger so in a full-fledged application, these will probably come in handy.

  • How to approach
  • Moving from no framework to framework is not an easy step (nor is it a hard step). You will have to get used to the conventions and new structure of your code. Personally, I feel that jumping right into something like CakePHP is a little intimidating. Therefore, what I recommend is familiarizing yourself with CodeIgniter first, using it as a stepping stone in the learning process. Develop a small application and see how you can implement models yourself so you will realize their role in an application and what CakePHP will eventually do for you. And possibly, you will find that the easier-to-learn CodeIgniter is enough for your application, saving you some precious brain cells.


zen perfect does not accept donations but would appreciate it if you Digg!


About this entry