Four reasons to hate CakePHP
A follow-up has been posted here
Before starting a project recently, I spent some time doing some research comparing CakePHP and Zend Framework for rapid development. I noticed that of the few articles out there, not many of them where able to offer any advice on using either framework for a new project. In most blogs, it seemed to come down to preference. My goal today will be to steer you away from Cake.
This article is intended for those that are familiar with the concept of rapid application development, and the benefit of using a framework such as Zend or Cake. If you want more information on why you would use such a framework, This article is outside of that scope.
It’s worth mentioning that CakePHP and Zend Framework aren’t the only popular open source rapid application frameworks out there. I’m only focusing on these two frameworks because I have the most experience with them, and can offer useful insight into their strengths and weaknesses. If you’re interested in other frameworks, have a look at any of the following.
Other Popular Frameworks
- Symphony - Built in Doctrine ORM.
- Zym Framework - a fork of Zend Framework, developed in parallel.
Cake is Heavy
Staying out of your way is a very important for many aspects in life, including your application’s third-party framework. You want something that provides functionality and structure, but allows you to fulfill your own needs in your own way.
Cake is no low-calorie meal
There’s nothing lightweight about it. Cake tends to get in the way of your application by requiring your application to be built on top of (instead of along side of) itself. When cake is bootstrapped (configured), it will look for your application specific configuration files in a hard coded file location that it expects. Although you can predefine the defines (which is a whole-other reason to avoid using cake) it uses to determine paths, you’ll never be able to completely seperate cake from your life without modifying cake itself.
Code and Feature Management
One of my cleints’ websites is was written on top of one of the Cake 1.2 alpha releases from a few months ago. (By the way, did no one tell the developers that in software engineering “alpha” release is not meant for the public?) I recently upgraded to 1.2 Release Candidate 4 and had a few problems. This is to be expected when you’re using any non-stable version of anything, but what I didn’t expect was API changes. I don’t mean additional features, I mean changing APIs. Granted they were few and far in between, but they were still unexpected.
Hanging on to Old Times
The most annoying thing to me is that Cake uses PHP4 style objects. I feel safe in saying that any community software being developed today that believes hindering best practices in order to support an obsolete (in the loosest of terms) version of software is not very forward thinking. No class members or functions have access modifier, and I don’t remember seeing any type hinting whatsoever.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // This is Bad! class Animal { var $kingdom = 'Animal'; function foobar() { //do something very private } } // This is GOOD! class Animal { private $_kingdom = 'Animal'; private function foobar() { //do something private } } |
No Namespace Consideration
Cake uses very generic class names with no consideration for names pace collisions. By using cake, you’re forcing yourself out of using generic class names in your own application (which is a better place for generic names to be!). Want to name a class `Controller`, `App`, or `Model`? Too bad — cake has claimed those names for you!
Another horrible practice of Cake’s is using global functions. Hsughughugh. I cannot begin to tell you how painful and fragile this is. All it takes to cure a few of the problems this creates is to wrap them in an abstract class! I don’t know why they would rather have the function uses() in a global namespace instead of wrapping it in a class as `Cake::uses()`. Some (maybe most?) have been fixed in RC4 (you use `App::import()` instead of `uses()`), but they still allow the abuse by keeping the functions there.
Conclusion
If you are reading this article, you’re probably at a crossroads between using CakePHP or using some other suite. I could go on and on about why I personally hate cake, but when it comes down to it, the decision is yours. Despite my gripes, Cake is still a good tool to get a simple website up and running quickly in a structured manner, without reinventing the wheel. Just make sure your website will never need to be scalable, and that its codebase will never grow beyond the small flexibility it offers. I’m personally experiencing this pain right now.
Great for mom & pop, but corporations shouldn’t dare
That’s how I once described my thoughts on using Joomla as a foundation for websites to a potential client. I think I’ll go ahead and reuse that for this article.







I am sorry but your arguments are not good enough to keep people away from CakePHP.
CakePHP has some weaknesses, I know. Some of them are mentioned here: http://www.slideshare.net/pcdinh/how-to-learn-to-build-your-own-php-framework-presentation
As I mentioned, CakePHP is great if you need to get a simple application out the door quickly. In fact, that scenario defeats everything I wrote. As soon as you need to scale or make the application highly configurable, you’ll hate the decision, though.
The next post I’m working on is “4 reasons to love Zend Framework.” I think the two posts will play well together.
I know one site that was built with CakePHP.
When it was small and not so popular, it was great. It was built quickly and the developer could spend his time on other tasks. However, when the site went popular, it basically slowed down to a halt. It is so slow that it takes 30 seconds for a blog post to load. Seriously.
What other frameworks for web development would you advise, in any language? Django?
Thanks.
P.S. Typically, placing the buttons of social websites at the bottom is better, because the readers will be more in the mood to share *after* they read your post. You can test it, I guess
I’m a big fan of Zend Framework, but I want to give Symfony a shot since it was built with Doctrine ORM natively. Ruby on Rails is praised by everyone, so that deserves some recognition
I’m honestly not familiar with many other frameworks.
I think you’re right about the buttons. They’ve been moved, thanks!
@Yuri: Cake is getting much faster. The recent RC3 speeded up the bootstrap process tenfold. See http://bakery.cakephp.org/articles/view/release-cakephp-rc3-the-rc-of-triumph
“[...] that *its* codebase will never grow [...]“
Thanks
Late night grinds turn into grammar catastrophes rather quickly.
Try Code Igniter. It’s light, it’s fast, it offers most of what Cake offers and it’s very easy to learn. Not only that but it gives you wat Cake restricts: freedom. If you don’t like the way Code Igniter implements a feature, you can easily overwrite the feature.
Want a different DB abstraction class? No problem. Don’t like the standard Method Model ? No problem. Instead of trying to learn things the ‘Cake’ way, Code Igniter just works, saves you time, and gets out of the way if you don’t want it there.
I would say that you are describing 2 well known things (just from your point of view): convention over configuration, and php4/5 compatibility of CakePHP 1.2 - things I can live with. You can be sure that CakePHP is not going to keep PHP4 compatibility for ever, though.
AJ, I’d like to see you do a 4 part series here. 4 reasons to {love|hate} {CakePHP|Zend Framework}. I think some of your reasons for hating CakePHP are considered features by others. I know one of my reasons for hating ZF is considered a feature by others.
That sounds like a good idea
After all, it’s not like Cake doesn’t have it’s place… and Zend Framework could also be the wrong choice in certain cases.
I’ll get started.
Hah, so what you’re saying is that .NET is bad because you can’t call your classes “String”, “Bool” or “Int32″? I mean, yes, you can, but in a different namespace. So, is Cake to be blamed for the lack of namespaces? I just hope you’re not suggesting names like CakeModel, because that just plain sucks. I guess PHP is also bad because you can’t have a function such as fopen(), right?
“you’ll never be able to completely seperate cake from your life without modifying cake itself.”
If you have to modify cake itself, delete the project and start over, there must something terribly wrong with it.
And PHP5 is planned for 2.0 AFAIK, although I agree that it would be nice to have it now.
Although your arguments are true *to some extent*, the article should be called “four reasons why *I* hate cakephp”, or “why cakephp doesn’t suit my particular needs”. No need to scare people away from a decent framework.
That’s hardly the same thing - Sting, Bool, and Int32 are built-in data types. I’m not complaining because I can’t manipulate the native langue. Also, you wouldn’t ever have that problem with ANY third-party software in .NET because namespacing is a core feature of the language. In PHP it’s not (until 5.2.6, but even still it won’t be a CORE feature).
So then you agree that this problem will be solved with namespaces in PHP?
I mean, if I can have this in .NET:
class Blast : Form {…}
why is it wrong to have this in Cake:
class Blast extends Model {…}
I think the lack of namespaces is a flaw of PHP, cake has nothing to do with it. Would you agree?
It’s definitely a flaw of PHP. It’s a problem that all php projects inherit, but a well designed project overcomes it. For example, Symfony prefixes it’s classes with `sf`, and Zend and Doctrine use packaged class names like `Zend_Form` or `Doctrine_Record`. This makes name space collisions highly unlikely, and keeps the third party code out of the way of the application itself.
class Person extends Cake_Model {}
instead of
class Person extends Model {}
what if your specific application has a model that’s literally named “Model”? That would be OK when namespace collision is not a concern:
class Model extends Cake_Model {}
Namespaces in PHP will help treat the problem, but it definitely won’t cure it. Since they’ll be very new, only the most cutting edge projets will support them. I’d say it’d be at least a year after they’re available until using name spaces becomes a common practice in PHP projects. After all, we’re talking about a language that won’t fix their inconsistencies in order to stay backwards compatible with versions that were released 456 iterations ago
I have to agree with Dr. Lecter. Your headline is fearmongering, and these are really personal reasons for you. Hence my earlier comment for you to play devils advocate.
But you’re grasping here, if you *need* a model class called model, use a thesaurus and pick something else like “tooSkinnyChick” or “babeWhoWishesSheCouldEatMore.”
To be honest, prefixes are a very intense pain the ass and I tend to avoid them. Surely, there must be a reason people gave up on prefixing class with C, private variables with m_ etc..like in the Hungarian notation. Readability perhaps? Of course, that’s just my personal preference.
Now, “Zend_Form” does solve the problem, but only temporarily. When namespaces finally do come to life, cake is going to have an advantage. Additionally, when you have 50 “Zend_” classes, the “Zend_” part brings a lot of pain when it comes to code assist i.e. intellisense. When I have a Model it is usually enough for me to type “Mo” and ctrl+space. Imagine the pain of typing “Zend_M” every time.
If you do have a model called “Model”, there is always an alternative. Is it a FashionModel? ToyModel? AirplaneModel? I’d rather turn things around: you’re trying to use a generic name in your project. Just think of if this way: are you going to say that PHP is terrible just because you can’t have your own fopen()?
But then again, I see that you are a contributor to ZF, and probably love it, and I’m in love with Cake; there’s a slim chance we’ll change our mind..
Yes, I won’t deny that I’m biased
But to be fair: The project I’m currently working on is the second I’ve seen drop Cake and move to Zend Framework due to scalability issues.
I would agree that Cake will be on-par for use with name spaces once they’re available. That’s a great point. Hopefully you’re correct and PHP5 style OOP is implemented in 2.0, though.
I like how you first lament Cake for late changes in the 1.2 API, and then complain about 1.2 legacy global functions still being present in the core.
Also, when I need to perform a topological sort to determine Library dependencies ( http://phpimpact.files.wordpress.com/2008/07/zend-blog-db-hor.gif ), I tend to steer clear.
Your actually quite wrong on most points. Ignoring the academic problems (read: “not real-world problems”) associated with missing namespaces, and how “bad” it is not to have access modifiers (even though there is hinting and even protection from the dispatcher in the case of controller methods - you just didn’t look enough to see them), I’ll point out just one:
“…you’ll never be able to completely seperate(sic) cake from your life without modifying cake itself.”
Really? The front controller (index.php) is part of your app and not at all part of the cake core. All models extend AppModel. All controllers extend AppController. Those are yours and belong to your app, not to the core. And using simple inheritance, you can override individual methods of the core classes, and if you so choose stop extending the parent class altogether. Not only does Cake thus allow you to separate itself, it allows you to do it bit by bit, without having to touch your code in many places. Now that IS “heavy”!
Personally I think you should save ‘hate’ for more important things. Or at least know a little bit about what it is you’re hating.
When you love some thing there isno need to prove it The best but when you blame some thing you must come out with valid reasons.
thanks
This post has generated a lot of (mostly) negative feedback, so I’ve decided to take another approach.
I will be writing a part 2 with real-world Cake horror stories over the next couple of days. I hope yo have you all comment on that one as well
Thanks for the feedback so far.
I can only hope your follow-up “horror stories” are as entertainingly ill-informed as this was.
Please be sure to include plenty of details so we can all tell you where you went wrong and why. Hehehe.
thanks for quick reply!!
i will be waiting for your next blog post
A.J. Brown: “But to be fair: The project I’m currently working on is the second I’ve seen drop Cake and move to Zend Framework due to scalability issues.”
What sort of scalability issues did you run into? I’ve run a pretty high traffic site on Cake with no issues. If anything the 3rd party forum software is always the issue. Maybe the sites you were running had much more traffic than mine.
Just curious as to what sorts of issues you ran into. Also, the firefox addons site is built on Cake (AFAIK). Seems to run pretty smoothly and I’m sure they get a ton of traffic.
Can you elaborate on the scalability issues? Just so we know what to watch out for.
very eager to read your next post.
about cake’s scalability and performance, sites like livemocha.com and addons.mozilla.org are running on cake. i dont seem to find any problem there.
its clear that you prefer Zend Framework, but all frameworks have their good part (also bad part).
Ok, I don’t have any eyes left to blacken. A follow up has been posted. You guys have way too many good points to ignore them
Holy shit, your calling CakePHP heavy? Have you even looked at Zend or Symfony, your joking right.
And the fact that it caters to PHP 4 because it doesn’t have access rights (public, private, etc). How does that hinder the framework in the least bit?
You dont need namespaces everywhere, you know how annoying it would be to do something like this: String::truncate(), when you know off the top of your head what truncate does.
Needless to say, you know you were not just wrong, you were somewhat unprofessional - study the client case and all requirements to get the job done, accept the job and DEAL WITH THAT - and nonsense - based in what you came across this impressive dumb-and-all-so-wrong-and-useless assumption: “great for mom & pop, but corporations shouldn’t dare” ? …
Well I got a full company running cake 1.2 based apps since it’s very beta version, and guess what? They are huge, scalable, with high performance and extremely reliable.
Don’t blame a whole project just because a) you can’t get your crap done using it and/or b) you run trough shitty code, made by lazy and porky developers - it doesn’t matter the framework you are using, it can be the most magical, light and useful piece of software in the FOSS world, regarded on greatest companies… there will always be bad programmers using it, and they will make it look like a joke.
Dont leave out CodeIgniter. It has 100% full documentation and is the fastest of all the frameworks. You can use the Zend Framework with it to make up for anything you might want that CodeIgniter might not have.
First of all, sorry my English
I liked CakePHP before I met CodeIgniter, where I found the most flexible and fast framework out of there.
I think you must take a look @ CodeIgniter. PHP’s creator, Rasmus Lerdorf some months ago said that he liked CodeIgniter because “it is faster, lighter and the least like a framework.”
Talking about other frameworks for rapid application development I think the best is Django (Python framework) which makes you to develop REALLY fast. It has an autoadmin area for all your projects.
I’ve used it sometimes to develop a control panel in my local server to control a remote application written in PHP.
I’ve been using cake for a year, but
I’m very newbie to scalabe websites,
how do you measure that ZF is more scalable than Cake?
agree with your Rafael. when you are using a framework, you are completely yourself. its after all not a CMS, that you will expect it to take care of everything itself. its your own code that matters.
‘garbage in, garbage out’.
1. I’ve configured multiple sub domains to use the same cake install w/o a problem. Changing paths isn’t difficult at all, I mean for god’s sake there is a simple defines file with the paths.
2. Alpha level code is often released to the public. Microsoft did it with Silverlight even. It’s actually a good thing to release alpha code since people can start to play with it and report bugs.
3. If the release is not stable, don’t expect backwards compability. Are you serious right now about these “issues” with Cake?
4. If I’m not mistaken, pretty much all of the popular PHP frameworks (except for Zend) support PHP4. Sorry to say, but a lot of websites are still running on PHP4 so at this time it would be unwise to stop supporting it when PHP itself still does. I have heard that the Cake team plans on stopping support for the next version.
Okay, you managed to say nothing about the actual framework. All you said was about the programming style and ethics of their team.
Some more valid questions that you can answer: How is Cake heavy? What features aren’t good? What is it missing? How is it difficult to learn?
@dr. Hannibal Lecter
class Blast : Form {…}
Your piece of code is not a .NET specific thing. This is just the syntax for specifying inheritance in C++ and languages influenced by C++ like C#. If you are working on a large scale system your “.NET” code should look like this:
namespace MyAppName.Forms {
class Blast : MyFrameworkName::Form {
// declarations
}
}
Languages like C and PHP (<5.3.0) don’t have real namespace support. so… we need to emulate namespaces by using prefixes:
void
gnome_accessibility_module_init (void)
{
// C code
}
or
class Mage_Strikeiron_Model_Taxrate extends Mage_Core_Model_Abstract
{
// PHP code
}
Hello Brown,
I don’t think that using CakePHP scalability is not possible.
From reading the topic title, i understand that you are a fan of Zend framework. Anyway let me know what kind of Scalability you are speaking about coz, we developed 2 websites with large code base but with no issues.
One thing i have to say is CakePHP has simplicity along with the robust, extendability, compatibility and all of this scalability.
Let me see in your second part of this Post (Reasons to love Zend Framework). However each framework and language have its own features defined for it and it is not wise to compare with others. A wise developer will do comparison but select the framework/language for what he require.
Hope this clears why and when you need to love Zend or Cake framework.
Regards
Xavier Raj Antony Samy
Amazing!
“Just make sure your website will never need to be scalable, and that its codebase will never grow beyond the small flexibility it offers. I’m personally experiencing this pain right now.”
Just as a note, anyone who says something is ‘impossible’ has already given up. As an object lesson in that, we run an very high volume (300 million page views a month) cluster running our 15 city newspaper sites. Our baseline application framework is CakePHP. Not 1.20, but 1.18. That framework (one physical instance on the disk) serves all 15 cities (and 3 smaller sites)
We’re talking (in aggregate) approximately 8 database servers, 1400+ tables, and about 4 meg of actual application code (not including Cake), servicing about 30 major application ’subsections’ with a new subsection coming online every month or so (including some that were totally unexpected)
A framework is a tool, not a panacea, nor is it a silver bullet. There’s not a framework out there that doesn’t have flaws in either it’s vision or it’s implementation. But careful and well-considered systems and application design can fix a multitude of perceived weaknesses and create extremely scalable systems.
Even with Cake 1.18.
After reading all these comments I can say that CakePHP users are a strange mix between JavaScript cut-n-paste Webmasters and PHP 4 procedural programmers from the 90s.
For me, Cake is like Visual Basic and Zend like .NET. And there are a lot of VB developers out there who don’t understand why .NET was created.
Really Chucho? Cut-n-paste webmasters and procedural programmers? Would you dare to elaborate on how did you reach that conclusion?
Also, how is cake like VB? I don’t see it that way because cake is not a prostate exam. VB developers normally don’t understand anything, but I don’t see how is that relevant?