CakePHP: Baking in frustration
Sometime back, I posted about my first experience with CakePHP. I installed the framework and went through the tutorial on building a simple blog application, and said “I was quite impressed”.
Now, after 3+ development weeks trying to build a real-world application, I think, maybe I was too hasty to draw that conclusion.
Baking in frustrations
During these 3 weeks, I have managed to build my own component, my own plugin, incorpoated ACL logic into the application, throughout which it has been nothing but frustration after frustration.
My biggest grouch has to be the poor documentation. I know it has been mentioned in many blogs before this, but I just have to say it again. For a framework like Cake, which reportedly make things happen “automatically”, good documentation IS the key.
In particular, I had a really frustrating time getting grips with plugins. I got errors when I tried associations between 2 models within the plugin, and I just couldn’t understand why it was so. It turned out that I had to use App::import() function within my PluginAppModel definition in order for the models to be recognized.
The other problem I had with plugin was the ambigious url between a plugin and a model. Let me explain. Let’s say I had a plugin called “seo”, in order to call the plugin, the url would be
http://[host]/seo/[model]/[controller].
So if I wanted SEO reports, the url would be something like
http://localhost/seo/reports/index.
So naturally, I would like a default page for http://localhost/seo/, but CakePHP will flag a missing model error if I did this.
I was trying every which way, like creating a dummy seo model and controller in /apps/models/seo.php, but the error still came up.
Eventually, after many many attempts, I ended up with defining in /config/routes.php, what CakePHP should do if it finds /seo url. Untill now, I still don’t know if this is a hack or it’s the real way of solving this ambigious url issue. In any case, since it works, I moved on.
Getting help
Help for me, came from doing Google searches for cakephp blogs and commentaries, and accessing CakePHP Google Group. A lot of answers came out of digging through these resources, but it was time consuming and doesn’t always yield any tangible results.
More frustrations ahead
It would seems that CakePHP 1.2 RC1 has been released, but be prepared for some more problems ahead as it reportedly have done away with some past conventions, and did not offer any backward compatibility. So applications written before RC1 will not work.
All this just makes me want to thrown in the towel and switch to CodeIgniter.
Definitely not for beginners
In my CakePHP first look, I pondered whether this framework was suitable for PHP beginners. I think the answer is now a definite NO. Without good documentation, beginners are just going to get lost in this framework.
Now that I’m partially through my application, I don’t really have a choice but to keep going and finish it up. But surely, after that I’m going give CodeIgniter a go and see which one will win me over.
May the best framework win!
- First look at CakePHP
- CodeIgniter: Extending the native ‘Model’ and make it your own.
- CakePHP: Using scaffolding for rapid application building
- CakePHP: Working with ‘Associations’
- Google Analytics API class for PHP






I’ve just upgraded a 40+ Model CakePHP 1.2 app to RC1 with no issues.
“but be prepared for some more problems ahead as it reportedly have done away with some past conventions, and did not offer any backward compatibility.”
I believe nothing has been ‘broken’. You will get ‘depreciated’ warnings in debug mode (along with instructions on what changes to make) but your code should still work.
IMHO, no framework is suitable for a beginner to PHP or any language come to that. Learn the core language first, then move onto frameworks once you have a good grasp of what’s going on under the hood.
Keep going with Cake! The documentation is improving all the time
Dude,
I feel your pain. Cake doc’s suck! There I said it. There’s nothing worst then having to dig through the Cake code to figure out WTF is going on.
To top things off, you get hammered in the forums for asking relevant questions or no answer at all.
BTW, performance in 1.2 RC1 bytes. I guess that’s the price you have to pay for automagic. Sure, you can write a couple of lines of cake code that would save you 100 lines of PHP code. But if performance sucks. Forget about it.
My boss laughed at the idea of buying faster servers.
Hehe I feel your pain, after first trying Cake and extensive research I tried Code Igniter next. I then moved onto Kohana which is nowhere near as well documented (including having tutorials still up for things that have been removed or no longer work) so back to CI I go…and these are supposed to be the ‘easy’ ones.
I’ve been developing with CakePHP now for about 2 weeks, and I have to say it’s super powerful… if you follow the conventions… if you can find documentation on what the conventions actually are.
Yes, the documentation is pretty horrible, but I’ve resorted to idling in the official irc channel on freenode (#cakephp) and the people there (including some devs) are helpful. Very often they will respond within a few minutes as well. I highly recommend investigating this support method as you’ll get quicker feedback on problems.
Have you tried Symfony Framework, it has excellent documentation and has a vibrant community.
Give Symfony A Try!
http://www.symfony-project.org
Anonymous Crowd.
Instead of CodeIgniter (which is yet another PHP4 framework), why not try symfony? Symfony is full PHP5, and has quite a few similarities to CakePHP in terms of offered functionality and features. It has, or so I’ve heard by a lot of people, probably the best documentation for a PHP framework currently available.
Thanks all for your comments. Maybe I should add that even though there has been frustrations along the way, I think, this is just growing pains. The lack of docs just makes the learning difficult, but once learnt, Cake will reward - no doubt. Just that it shouldn’t really be this hard.
@Richard:
Yes, regarding RC1 backward compatibility, maybe ‘will not work’ was too harsh. But I don’t really like it when after an upgrade, it throws a whole bunch of warnings. I guess that’s just a preference thing.
I’m sorry to hear about your fustration.
But please note a few things about CakePHP (1.2).
You were using a beta edition of a framework, expect things to break whhen you update. And for gods sake, use a stageing server before you update your live sites.
Re. your models in plugin issue.
You do not need to App::import them.
array(’className’ => ‘Seo.Test2′));
}
?>
would make cake auto-select the right plugin/model for you. No need to do anything by hand. (This should be documented).
Re. your route / link issue
You can use Router::connect to fix that
Router::connect(’/seo/:controller/:action/*’, array(’plugin’ => ’seo’, ‘controller’ => ’seo’, ‘action’ => ‘index’));
Or just
Router::connect(’/seo’, array(’plugin’ => ’seo’, ‘controller’ => ’seo’, ‘action’ => ‘index’));
to make sure it will catch your ‘root’ route for the plugin. (This should be documented in a blog or 100 around the net, if not already in the cakephp book).
Also, while the documentation is ‘lacking’ (1000x better than ever before anyway), the best wayt to really utilize the framework is to - well, duh, browse the source code.
And if you dont have time for that, browse the test cases.
Most of cake has a test coverage > 50%, (probably more), and every feature you could wish for is tested there.
Just my 50c
array(’className’ => ‘Page’), ‘Setting’ => array(’className’ => ‘Seo.Setting’));
}
will load app/models/page.php as Page
will load app/plugins/seo/setting.php as Setting
No App::import required
ok, your blog is broken when i try to type ‘< ? p h p
it just discards it
@Christian
Thanks. At least you’ve confirmed for me that router is the way to do it for the link issue. It’s always good to have some affirmation that I’m on a right track.
Not sure what you mean on the plugin model issue tho.
I don’t think browsing the source code is really an option to make up for poor docs. But I get where you’re coming from.
I guess we can all do our part to contribute to the documentation effort. I have to also say that trac.cakephp.com was also a wealth of information. You just have to go digging for it.
Hi! I have used CodeIgniter, Symfony and Zend Framework on several projects before, imho Zend Framework tops them all with regards to performance and flexibility. Granted that there will be a learning curve, but give it a shot. Am in the middle of a project right now with Zend.
If you like PHP’s manual, you’ll love Zend Framework’s documentation.
With regards to having a default page for a plugin. It is possible, there’s no need to mess around with routing, because I use this technique to create a “Dashboard” page for my admin backends.
Assuming you have a fairly standard plugin - in your instance:
/plugins/seo/seo_app_controller.php
/plugins/seo/seo_app_model.php
/plugins/seo/controllers/seo_controller.php — This is the key file here
/plugins/seo/views/seo/index.ctp — This is the second important file
In seo_controller.php, right at the top underneath where you set var $name = ‘Seo’;, add a line: var $uses = array();
This will solve your problem, as Cake will no longer look for a default model for this page. Works just as well outside of plugins should you feel the need to have a controller without a model. And this technique is well-documented.
I second the recommendation for Zend Framework. It’s an MVC framework with great documentation. http://framework.zend.com
I started with CakePHP and although I was able to get my application running, it was not at all fun. Finding any decent source of info was near impossible without spending hours trying to dig up a blog or google code thread that commented on it.
My next project I moved over to Code Igniter, and so far have found it to be much better. There are a few annoying bugs that I continually hit with checkboxes, but aside from that, its a rather painless experience. 90% of the stuff I need is in the documents, and the rest comes up with a simple search in the forums.
Cake is a great framework. Complaints regarding performance can be trumped by utilizing caching. Cake is probably one of the more well structured PHP frameworks available.
The doc’s may be lacking, but if you stick with it, it’s well worth it- much more robust than CI.
I was a ZF developer for about 6-8 months, but switched to Cake and have been using it for just under a year. I had some frustrations initially as well, but after working through them, I haven’t regretted the switch.