This past month, the CakePHP team announced the launch of the alpha release of CakePHP 3. The Cake development team considers version 3 to be a game changer, so with the alpha release of version 3 now hot out of the oven, this article takes a fresh look at CakePHP 3 as an effective modern framework for PHP development.

This CakePHP 3 treat is fresh out of the oven.

A Brief History

These days, there are so many options when it comes to PHP development. As PHP has matured, more and more PHP Frameworks have come onto the scene, providing developers with a wide array of choices. But it hasn’t always been that way.

Back in 2005, when PHP 4 was still the standard, there were no PHP frameworks and developing an object oriented coding approach in PHP was certainly a challenge. It was then that CakePHP emerged – the first-ever PHP MVC framework. In the nearly 10 years that have passed since it was first released, CakePHP has continued to evolve, maintaining a healthy market share of PHP developers.

Just how popular is the CakePHP framework? It is ranked in the top 4 most popular PHP projects on GitHub, of around 130,000 projects, with over 18,000 members in the CakePHP Google group with 32,000 topics. With 270 contributors to the code, and 320 contributors to the documentation, there is no denying that CakePHP has a big following. CakePHP’s current widespread and growing popularity is well summarized in an article by James Watts, core member and community manager of CakePHP for the Cake Software Foundation, who I interviewed in the course of writing this article.

With version 3 of the framework now available, CakePHP is most certainly expected to remain a leading force in the PHP world and a major contender amidst today’s varied landscape of PHP frameworks.

What’s new in version 3 of CakePHP?

This review is based on the alpha release of CakePHP 3.0, which incorporates a number of new features and enhancements including:

  • Better performance. Version 3 incorporates performance improvements to the bootstrap process, the routing process, and several parts of process for generating helper templates.

  • Enhanced components and helpers. Version 3 provides enhanced support for “flash messages” with its new FlashHelper and FlashComponent. In addition, the CookieComponent has been enhanced, making it easier to separate the configuration of cookie namespaces and the handling of cookie data.

  • Improved session management. Session management has always been a static class in CakePHP which has proven to be problematic in a number of ways. With version 3, you can now access the session from the request object $this->request->session(). This change also makes the session easier to test, and enables CakePHP to use PHPUnit 4.x.

  • Improved consistency of conventions. The application skeleton and plugin skeletons have been updated to use the same directory structure in order to be more consistent with one another.

  • Themes and plugins merged. A key goal of CakePHP 3 was to make themes more powerful and robust. Working toward that goal, it became apparent that what was really needed was for themes to provide the same capabilities as plugins. Accordingly, any plugin may now be used as a theme, which also simplifies packaging and redistribution.

  • ORM Improvements. Several API changes have been made to the ORM (Object-relational mapping). Most notably, it’s now simpler to specify deep associations for saving operations, and a couple of conventions have been changed to reduce the learning curve and confusion among new adopters.

In addition, there are a few additional features that are also planned to be incorporated into the beta release of version 3.0. Most importantly:

  • Internationalization and localization (i18n and L10n) feature enhancements
  • A replacement for CacheHelper based on Edge Side Includes
  • A new routing API for simpler and faster route declaration

Indeed, version 3 represents a significant upgrade beyond prior versions of CakePHP.

Why CakePHP?

While CakePHP has many great features, this review focuses on a few in particular that really help set it apart, namely:

Convention over configuration

CakePHP has always been about rapid and consistent development and, toward that end, CakePHP places a heavy emphasis on convention. Therefore, like Ruby on Rails (from which CakePHP drew much of its inspiration), CakePHP adheres heavily to the convention over configuration principle.

Conventions mean that a developer doesn’t have to think about “where things go” when learning how to use the CakePHP framework, since defaults for these rules are already put in place. While one does need to become familiar with the CakePHP conventions, once mastered, the developer can concentrate on core development, rather than needing to worry about where the code is placed and other configuration issues.

CakePHP’s conventions are in stark contrast to PHP itself, which is a fairly liberal language. As a result of its conventions, CakePHP helps to ensure more consistency in coding style and structure across multiple developers and even across multiple teams. By adopting a standard set of conventions, Cake strives to make development more consistent.

For a database schema, for example, CakePHP makes certain default assumptions in terms of how certain variables, table names, and fields will be named. Specifically, Cake expects that:

  • Table names will be plural (e.g., orders)
  • The name of the primary key field will be id
  • The names of any foreign key fields will be based on the referenced table name followed by _id (e.g., the foreign key into a customers table would be named customer_id).

To illustrate, let’s consider a simple review of two tables (articles and users) from a blog post database. In our example, we’ll say that an Articles “BelongsTo” a Users, and a Users “HasMany” Articles. These relationships would be specified as follows in CakePHP 3.0:

In ArticlesTable.php:
    class ArticlesTable extends Table {
        public function initialize(array $config) {

In UsersTable.php:
    class UsersTable extends Table {
        public function initialize(array $config) {

CakePHP assumes the default conventions and thereby automatically knows what foreign keys to look for (i.e., user_id in the articles table) when fetching any associations.

It is important to emphasize, though, that CakePHP 3 does allow for its default conventions to easily be overridden. For example, let’s say our foreign key in the users table was called author_id instead of user_id. Specifying this would just require the following two small changes to our code to let CakePHP know that we’re not using the default:

In ArticlesTable.php:
    class ArticlesTable extends Table {
        public function initialize(array $config) {
            $this->belongsTo('Users' => ['foreignKey' => 'author_id']);

In UsersTable.php:
    class UsersTable extends Table {
        public function initialize(array $config) {
            $this->hasMany('Articles' => ['foreignKey' => 'author_id']);

So, although conventions are indeed integral to CakePHP and definitely do have their advantages, overriding them when necessary is really quite simple, as we’ve shown here.

While some developers may prefer PHP frameworks (such as Yii and Laravel) that don’t rely as heavily on conventions, CakePHP conventions can in fact be quite advantageous. They can help dramatically reduce ramp-up time for a CakePHP developer when tasked with enhancing or maintaining code written by another developer, since they result in consistent coding structure and conventions across multiple CakePHP developers and projects.

CakePHP’s Object-relational mapping (ORM)

CakePHP’s Object-relational mapping (ORM) benefits greatly from CakePHP’s framework conventions. By setting out the database schema to Cake’s standards, you can quickly connect tables together through Cake’s powerful ORM. You’ll rarely need to write an SQL statement, as CakePHP handles things like table joins, hasMany, and even hasAndBelongsToMany relationships with ease.

Leveraging CakePHP’s ContainableBehavior, through your model associations you can specify which database tables and fields to select from an SQL query. This can go several tables deep, and through the ORM it is easy to rapidly construct highly complex SQL statements.

Incidentally, CakePHP’s ContainableBehavior is a great example of how CakePHP can simplify and streamline PHP development. It helps you search and filter data in a clean and consistent way and can also help increase the speed and overall performance of your application. (It works by temporarily or permanently altering the associations of your models, using the supplied containments to generate a corresponding series of bindModel and unbindModel calls.)

The challenge with the ORM is that it makes using SQL so simple that, if a developer isn’t careful, he or she can write inefficient SQL queries without meaning to. I have certainly seen poorly written Cake applications many times which haven’t streamlined their queries. These problems tend to surface a couple of years after a system has been deployed, when databases get bigger and badly written queries become increasingly slow.

The main issue here is that, prior to the latest CakePHP version 3, Cake’s ORM would by default retrieve any associated tables when performing a query. As a result, a simple “find all” query could potentially become quite bloated as the underlying SQL would retrieve all data from all associated tables. In version 3, this behavior is no longer the default. (And in prior versions of CakePHP, this default behavior is easy to disable by simply adding public $recursive = -1; to your main AppModel.php file.)

Overall, a review of Cake’s ORM shows it really does help streamline development and, if used correctly, is an amazing tool for building complex queries quickly. It is nonetheless vital that developers take the time to fully understand the ORM and to ensure that their queries are are properly optimized (as is true in any language).

Components and Helpers: CakePHP Libraries

One of the great features of CakePHP is the built-in libraries – Components and Helpers – that eliminate many boring, repetitive, and tedious development tasks. In the MVC context, Components help streamline controller development, while Helpers simplify view coding and logic (i.e., the presentation layer).

The PaginatorComponent, for example, auto-magically builds a next/previous page interface from a find query. Add the JsHelper, and suddenly you have AJAX Pagination, powered by your favorite JavaScript framework (jQuery by default).

A quick sampling of a other useful Helpers includes:

  • TimeHelper: Makes displaying dates and times a breeze, providing a suite of functions for formatting and evaluating time values.
  • NumberHelper: Provides convenient methods for displaying numbers in a variety of common (or customized) formats and precisions.
  • TextHelper: Aids in enabling links, formatting URLs, creating excerpts of text around chosen words or phrases, highlighting key words in blocks of text, and gracefully truncating long stretches of text.

And there are many more.

Criticisms of CakePHP 3

To be sure, every framework has its pros and cons, and CakePHP is no exception. Here are some of the most common criticisms leveled at CakePHP outside of this review:

  • “Legacy framework; bloated and slow.” This criticism is typically more of a historical one, with limited (if any) truth today. Supporting PHP versions as far back as PHP 4 has historically required CakePHP to deal with many of PHP’s own legacy issues. With the maturing of PHP, and with the release of CakePHP version 3 in particular, this allegation really has lost its validity.

  • “Overly strict and confining.” While there are clear advantages to the CakePHP conventions, there are those who criticize them nonetheless. Critics often argue that the conventions are too strict, but they fail to recognize (or acknowledge) that these conventions can be easily overridden. By adopting a standard set of conventions, Cake looks to make development consistent which, given PHP’s otherwise loose coding practices, should only be seen as a positive thing.

  • “Slow release cycle”. A slow release cycle is not necessarily bad. To the contrary, a release cycle that is too aggressive can actually be more problematic. In fact, part of the reason that CakePHP major releases take time is to ensure backward compatibility with earlier versions of PHP that are still widely deployed. Moreover, this conservative release cycle and emphasis on backward compatibility eliminates the need for major (and frequent) changes to your code when new versions are released. It should also be noted that the CakePHP 3 team is anything but slow when it comes to minor releases (bug fixes, patches, minor enhancements, etc.), which are released monthly. Similarly, most bug tickets are answered within hours of being posted.

  • “Not an out-of-the-box solution.” In contrast to many other modern “web app out of the box” PHP frameworks (such as Yii, for example), CakePHP purposefully looks to support and enable custom solutions. I have personally benefited from this greatly in developing a number of large, custom, database-driven web sites and applications.

  • “Uses data arrays rather than objects.” This is no longer true, as of version 3. In previous versions, any data would need to be stored and referenced as nested arrays (e.g., $user['User']['username']). CakePHP 3 finally addresses this, instead storing data as objects (e.g., $user->username).

  • “Poor documentation.” There is some validity to this criticism, in that CakePHP documentation doesn’t always appear to have been written with the beginner in mind (important information is sometimes discussed in just a sentence or two, whereas a few paragraphs of discussion would probably have been warranted). The Cake development team is aware of this and is working to improve the documentation accordingly. In fact, the home page of the CakePHP 3 documentation explicitly states a high level of commitment to the “quality, validity and accuracy” of the documentation. As CakePHP is a community driven framework, an “Improve this Doc” button is provided on every page of the documentation, enabling and encouraging CakePHP users to contribute their own additions, deletions, or corrections to the documentation.


All-in-all, nearly 10 years after its initial release, a review of CakePHP reveals that it remains a vibrant and formidable competitor to the many other PHP frameworks that have since emerged.

CakePHP is a complete and comprehensive development solution. The code base is mature and the functionality seems endless. Overall, Cake has been built to make development rapid, which is important not only for software developers, but also for investors. The biggest cost of software development is the cost of the development time, and CakePHP aims to reduce development time significantly.

CakePHP is a community run project. It can only get better as more and more people get involved. Having been involved for 7 years and seen the community continue to grow, I am excited about this next stage for CakePHP. The launch of CakePHP 3, and the maturity of both PHP and CakePHP, means that the framework will continue to get better and better.

If you are looking for a PHP-based solution that offers many benefits similar to Ruby on Rails (in terms of ease-of-use and convention over configuration), then give CakePHP a whirl. The CakePHP Blog Tutorial only takes a few minutes to set up and run though, or alternatively, CakeCoded offers a series of clear lessons to help acquaint a PHP developer with CakePHP and to get started using it. With these resources, you will quickly see the extent to which CakePHP can speed up and enhance your PHP software development efforts. Enjoy!

Michael Houghton is a Toptal Engineer based in Ireland with extensive CakePHP experience. He has developed over 100 websites with the framework, worked with the team at CakeDC (the commercial entity behind the CakePHP framework), has submitted various patches, and has helped with the CakePHP documentation.

About the author

Michael Houghton, Ireland
member since March 6, 2014
With twelve years of back-end development in PHP combined with a background in business, Michael brings a great balance of technical and business expertise to the table. He has experience with vanilla PHP websites, as well as CakePHP, Zend, CodeIgniter, PhalconPHP, and Laravel frameworks. He's also gained project management experience, leading teams and working directly with clients to build projects from start to finish. [click to continue...]
Hiring? Meet the Top 10 Freelance CakePHP Developers for Hire in October 2016


Paul Henn
Great read!
Nice article, very well written. Personally I love Symfony2 but it's quite hard to get used to it's ecosystem of "bundles" and even though it's modularized into independant components such as "http-foundation" I never really know how that works or what is it for, nevertheless I do enjoy Silex, it's another approach where you have more control over every part of code your app REALLY needs. I haven't tried Cake in a while, I'll probably give it a shot once they have a Release Candidate :)
Dr. Tarique Sani
Your ORM code examples are all wrong if you are giving it for CakePHP 3 namespace App\Model\Table; use Cake\ORM\Table; class ArticlesTable extends Table { public function initialize(array $config) { $this->belongsTo('Authors'); } }
Alex Anisimov
Guys, it seems that you have a little typo (or maybe mistake) in the block where you are describing convention over configuration principle implementation in Cake. Look at this sentence: "The names of any foreign key fields will be based on the referenced table name followed by _id (e.g., the foreign key into a *customer* table would be named customer_id)". A pair sentences earlier you'd said that expected table name for the model is plural noun, but in example with foreign keys you are using singular noun "customer". It's confusing a bit.
Alex Anisimov
Cake's array based data model is terrible actually. It's only my opinion, but I can't imagine what might be worse than to write something like $posts['Post']['Comments'] in your view. And one more shot: I can't find description of satisfactory data migrations implementation in Cake. And as I remember it always was a huge problem to integrate some third-part library, Not sure if something has changed.
Dr. Tarique Sani
heh! I see now that the title has been changed ;-)
Dr. Tarique Sani
Probably written by a content writer rather than someone who has actually taken time to review CakePHP 3 (which was mentioned in the original title)
Alex Anisimov
I don't remember what was the original title
Dr. Tarique Sani
A Thorough Review of CakePHP 3.0 - that still in the title of the page...
Michael Houghton
Hi Alex. The array based data models are changing in Cake3 - they will be $post->comments instead. There is a good plugin by CakeDC for data migrations:
Michael Houghton
Hey Alex - the example we gave was for Cake 2.x. I will look to update the example for Cake 3. The content is actually correct for Cake 2.x - TABLE names are plural, while index keys are singular. One of the big changes with Cake 3 is that the ORM is changing to make all model names plural, including the foreign keys. I will let you know once the example has been updated for Cake3.
Alex Anisimov
Frankly, I haven't looked at Cake (and haven't written any line of code with Cake) for a long time. So if things have changed it's fine. Congrats and so on.
Adrian Voicu
"e.g., the foreign key into a customer table would be named customer_id" - wouldn't that be "a customers table"?
Michael Houghton
It should be - I will update this, thanks Adrian.
Luyanda Siko
I had an issue when I was trying out the new Cake. Basically I have "MeetingAgendaItem" belongs to "MeetingNumber" and inversely "MeetingNumber" has many "MeetingAgendaItem". Getting records through the MeetingNumber table class such that it gets the related agenda items worked fine. The only problem however was to loop through the object array and create an array of my agenda items ending up loosing the object data structure and working with arrays... Any suggestions on how to traverse returned data where more than one table is concerned with the new ORM?
Saleh Souzanchi
That right, CakePHP is POwerFull
john j. rambo
CakePHP's the worst framework i've ever had to deal with!
Mark Scherer
Looks like the ESI/caching won't make it into the core after all, maybe more a plugin solution then. @ john Ignorance doesn't make a framework bad per se. Use other tools if you are not capable of handling this one. Thats why there are so many. People like/use different frameworks for different jobs.
Elvis Miranda
I have successfully developed two CakePHP applications back in the day (before moving full time to .net) but I'm seriously considering to work with Laravel for future php development, if I had to work with PHP based projects.
I had been programming in CakePHP 2.x for a couple of years and then changed companies and started working on an existing website in CodeIgniter 2.x. While CodeIgniter was very easy to use, it was missing lots of features that I had grown accustomed to in Cake (ORM, auth, unit tests, multi language). Every time I asked about a missing feature the answer was "we could probably find something on the internet" or "we could write our own". And my coworker made it clear how much he hated Cake. Turns out he had compared CI 2 to Cake 1 and had never looked at Cake 2. To me Cake 2 is far superior to CI 2 but I had used Cake 1 and could understand how it annoyed some people (slow, poor documentation). Now we are talking about migrating to a new framework and he is pushing for Laravel. I ran through a tutorial on Laravel and it seems kind of similar to Cake 3. Any opinions on which way to go? Since so much is changing in Cake 3 I'll have to learn a lot anyways - so better to learn Cake 3 or Laravel?
Michael Houghton
It is always going to be a bit of an opinion on Cake VS Laravel. Really, my advice is try both and see what you like. There is a lot to like about Laravel, but for me personally, also some-things that annoy me. I wrote about it here if you are interested:
Tiago Oliveira Farias
CakePHP is poor!
Yusuf Ibr.
I have tried several php frameworks, and I found that CakePHP is the best PHP framework which is very powerful but easy to learn.
Cameron Baldwin
Hiii .. Thank you for such a informative article. It is the most advanced, economic and secured framework available on the internet?Here at CyberNext .. we love to work on Cake PHP.
I've been using cake since the 1.3 days, totally get there where things that it did non-optimally - returning all associations (say you had a blog post and it had tags, comments associated with it, it would return all that stuff) in a array. The thing I liked about it was it was easy to set-up (Symfony at the time was a bit too verbose, same for Zend 1), CodeIgniter felt like Cake with all the extras stripped out, but I get why people liked that, after all many of us started before there where PHP frameworks. 3.0 is a whole different beat though, a lot of the concepts are the same (took me about 2 weeks to feel comfortable with it coming from 2.8) and a lot of it comes down to it keeps the good stuff (code generation, not too verbose, good speed), but uses composer, phinx (schema building) PHP 5.4+ (runs fine on PHP7). Not to start a flamewar, but I did try Laravel too, the ORM's both feel pretty similar, but I missed Cake's code-generation, last I looked there where some Laravel tools but not as easy as building a table in MySQL, type into the CLI something like "/cake bake all posts" and have it spit out all the code for a simple CRUD interface to that table (associations automatically detected if you follow the naming conventions). Sure you'll have to do a lot of work if you're planning on building Wordpress, but you can't beat that for just learning where to put files, etc. In short, it's a opinionated modern PHP framework that uses the some of the best of the PHP ecosystem - I'm pretty happy with it.
David Stephan
I am glad by following up with this useful information. All about CakeePHP in one place. Kool :)
Tomas Maly
Just wanted to mention that CakePHP's documentation is 100x better than Laravel's, despite Laravel being more popular these days. Laravel's documentation only skims the surface and in most cases is not enough for many use cases. I find myself on StackOverflow constantly, looking for answers.
comments powered by Disqus
The #1 Blog for Engineers
Get the latest content first.
No spam. Just great engineering and design posts.
The #1 Blog for Engineers
Get the latest content first.
Thank you for subscribing!
You can edit your subscription preferences here.
Trending articles
Relevant technologies
About the author
Michael Houghton
PHP Developer
With twelve years of back-end development in PHP combined with a background in business, Michael brings a great balance of technical and business expertise to the table. He has experience with vanilla PHP websites, as well as CakePHP, Zend, CodeIgniter, PhalconPHP, and Laravel frameworks. He's also gained project management experience, leading teams and working directly with clients to build projects from start to finish.