May 3, 2016

CakePHP vs. CodeIgniter

Using Model-View-Controller (MVC) frameworks are the way to go for developing websites today. Nearly all websites need basic functionalities like accessing databases, controlling user logins, templating, and more. WordPress deployments are great, but when needing to quickly build custom web applications, MVC frameworks like CakePHP and CodeIgniter are the way to go. Though these two frameworks have a lot in common, there are some key differences that we will explore.


Both CakePHP and CodeIgniter have some basic things in common:

  • VMC architecture
  • Routing
  • PHP4 support
  • Scaffolding/Templating

As Advertised

As advertised, one begins to see some differences between CakePHP and CodeIgniter. CakePHP is characterized by a few statements:

  • For rapidly developing robust web applications
  • For helping developers write less code
  • No Configuration – Set-up the database and let the magic begin
  • Extremely Simple – Just look at the name…It’s Cake
  • Extensible architecture

And CodeIgniter is characterized by the phrases:

  • A framework with a small footprint
  • A framework that does not require you to use the command line
  • A framework that requires nearly zero configuration
  • A framework that does not require you to adhere to restrictive coding rules
  • You do not want to be forced to learn a templating language
  • You eschew complexity, favoring simple solutions
  • You need clear, thorough documentation

We will look at some of these differences next, but it should be noted that even just these advertising phrases show a lot. It’s almost as though CodeIgniter promotes itself by being the solution to the things that most developers dislike about CakePHP.


First, let’s look at models. Databases are not only a central component to most any website but they are also frequently accessed. Thus, any framework should be harshly judged according to how good its methodology is for handling database requests. CodeIgniter has an excellent method for grabbing data from the database which eliminates the need for even having a model with most projects since most projects have simple and straightforward database layouts. An example query using method chaining would look like the following,

$publishedAuthors = $this->CI->db->distinct()->select(‘user_id’)->from(‘articles’)->where(‘status !=’,’pending’)->get();

As you can see, even complex queries could be written using method chaining in the CodeIgniter framework. CakePHP on the other hand automatically loads the model for every controller and will throw an error if one isn’t found, tough one can set the controller to not use a model. The query methods are not as intuitive and are more rigid,

$publishedAuthors = $this->Article->find(‘all’, array(
‘fields’ => ‘DISTINCT Article.user_id’,
‘conditions’ => array(‘Article.status !=’ => ‘pending’)

As you can see, the methodology isn’t nearly as similar to MySQL as CodeIgniter’s and therefore less intuitive. However, it does have some fancy automation features. It automatically makes associations between framework methods and the database. For example, one could grab all the values in the users table where the status field is zero by,

$users = $this->User->findAllByStatus(0);

CakePHP automatically associates the characters after the ‘findBy’ or ‘findByAll’ methods with fields in the database. Though CakePHP’s models are much more powerful in that they are thoroughly automated, the amount of forced automation is more often than not a hindrance, and overkill at that.


CakePHP is automated to the max. Every controller requires a model, and every controller’s method requires a view. All these are automatically loaded using the default layout/scaffolding template and the naming schemes are tight. If the controller is named ‘Pages’, it must have a folder ‘views/pages/’, a model ‘Page’, and a database table named ‘Page’. When it comes to user authentication it is even more so. It uses the ‘Users’ controller by default which requires a table named ‘users’ with an id field named ‘id’. And this is just the beginning of all the tasks that CakePHP automates.

CodeIgniter has a very different approach. It only automates what you want. If you want to load a model or a view and/or use scaffolding then you specify it. And, don’t be deceived, it is not more work than CakePHP because with CakePHP you are forced to create the various files with the right naming schemes, whether you use them or not. In CodeIgniter you only use what you specify and the logic flow is much more apparent when looking at what is going on in the controller.


Because of how automagic CakePHP is, it is also much more slow. How slow? Well, one benchmarking test run just a few months ago using the Apache Benchmark (ab) tool put CodeIgniter at 9.4 times faster. The test used 10 users hitting CakePHP and CodeIgniter with requests over 60 seconds. CakePHP completed 3,450 requests and CodeIgniter a whopping 32,544. CakePHP processed 57.50 requests per second and CodeIgniter processed 542.37! Other benchmarking tests show the same, one shows CakePHP at 6.10 requests per second and CodeIgniter at 90.88 requests per second–15 times faster!


I would have to agree with Mr. Jonathan Snook on this point who notes that CodeIgniter’s documentation is much more organized and thorough than CakePHP’s. I know that I have always found what I needed on their site, though that hasn’t been true for CakePHP in my experience. Yet, perhaps that is because CodeIgniter is much a much more simple and straightforward framework. Even so, both frameworks have solid community support which is where a lot of great code examples and plugins are found.


The claims that CakePHP is simple as cake are ill-founded. It is more advanced than CodeIgniter because it is more automated, but that automation is not easy to understand. CodeIgniter balances simplicity with complexity, that is, it is simple to understand how it achieves complex tasks, and that is exactly what makes it a better framework. As Mr. Snook stated, “[e]verything is in plain sight and you can really see how things work.” Though he wrote in 2007, I find his analysis still accurate.

One article compares CakePHP and CodeIgniter to boxers, the first being a “heavyweight fighter with guns to show” and the second a “lightweight fighter, quick on the feet.” In Round One, “CodeIgniter is already throwing punches left and right while CakePHP is just warming up.” Developers want to be able to start throwing punches in round one with their websites, and CodeIgniter allows them to do it. For new developers and those who haven’t used MVCs it will take a larger amount of time to understand the CakePHP framework to even be able to get in the ring before “throwing punches” and making websites.

Every developer and every website each have their own characteristics that make them who they are. CakePHP forces the developer and the code into very tight boxes. On the other hand, CodeIgniter gives the developer creative freedom and allows websites to be easily shaped into their own character while still fitting the code into a logical and organized framework. Most of all, keep in mind that the essential goal for using any framework is to develop code in a logical and organized manner. If even CodeIgniter is too cramped for you, create your own MVC framework or try out Dave Hensley’s PunyMVC, the “lighter-than-air, no-nonsense, zero-learning-curve, lightning-fast MVC framework in less than 4/5 of a kilobyte (uncompressed)!”

About Joe Purcell 32 Articles
Joe Purcell is a technology virtuoso, cyberspace frontiersman, and connoisseur of Linux, Mac, and Windows alike.

Be the first to comment

Leave a Reply

Your email address will not be published.



Please enter the CAPTCHA text