In my new explorations of PHP web application development, it seemed a good idea to get a look at both CakePHP and Symfony. Both of them seem to be PHP’s answer to Ruby on Rails.
The approaches are similar and different to each other. I set up both on my laptop, and tried out some really simple app development. In Cake, the database build is separate from the application building (you do it yourself), whereas in Symfony, you use Symfony to build the database with schema files written in YAML. Then, you build forms and such using the schema as a foundation.
They both use the MVC pattern, and both use object oriented PHP, which is great. I got a lot further with Cake in one evening of playing with both than I did with Symfony. At this point, I really prefer Cake – it feels like it jives with my own coding sensibilities better. I also don’t like the overhead of learning YAML. I can imagine, though, that the Symfony approach can be powerful.
Looking at Ohloh, Cake is more popular than Symfony (on Ohloh, who knows about in general), but Symfony has a lot more developers (81 vs 17). They both have good documentation and active communities.
For now, unless something strange happens, I’ll settle on Cake – although I’ll not be spending too much time on it, since I’m working hard to grok Drupal. But perhaps a cool project will manifest, and I can use it.
Update: I learned that Yahoo and delicious have a huge investment in Symfony (which, I guess, might be why they have so many more developers.)


{ 2 trackbacks }
{ 8 comments }
I think it’s safe to bet that YAML would take you 5-10 minutes to get, so that shouldn’t be a big barrier.
I went through a similar exercise in January (http://slagwerks.com/blog/index.php/2008/01/23/puttering-around-with-symfony/) and noticed a few major benefits of symfony over cake:
- the database integration is a huge timesaver
- symfony makes it easy to write tests for your app
You may also want to give CodeIgniter a look-see. It doesn’t do as much magic under the hood and has a smaller universe of conventions, so it’s easier to get going with. I’ve really liked working with it for small to mid sized projects.
Michelle-
I don’t understand three quarters of what you’ve written here, but I am so very grateful for what you do. For those of us struggling to understand as many aspects of web development in relation to NPO’s as we can, I wanted to say thank you and please keep it up.
tjs
I used cake 1.2 for close to a year and I’m currently learning symfony. With cake many things flowed pretty quickly and easily. I was happy and even got friends to use it.
As my app grew from a couple tables I started to run into limitations of cake’s ORM. There’s for example, no sane way of specifying joins. Turns out joins are only performed on hasOne and backwards on belongsTo relationships. You can’t tell it, I need a join here. You have to rely on the ORM’s magic to make that decision.
There’s also that you can’t easily paginate multiple models in a single page. Example: Author hasMany Comments, Author hasMany Article. Viewing the Author page one should be able to see Related Comments and Related Articles. In fact that’s how the baked forms and scaffolding show this data. Paginating those 2 is a different story since by default the parameters that specify the page you’re in do not distinguish which model you need to paginate. For what should be a nice condensed view you have now to have separate pages.
There are tricks like this http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/ which I personally find ugly. For pagination I understand you can have multiple paginators per page with ajax but from what I’ve seen the whole system asumes you’ll be paginating one thing at a time so it’s more of a workaround than anything else.
For me the point of using a framework is to keep code clean and me happy. These and other things have the opposite effect. As much as I dislike symfony’s verbose style and its multitude of config files it turns out they made the right choice (for me) by chosing to use well established ORMs instead of taking on the task of reinventing the wheel.
I really liked cake. I just wish it didn’t suck at the things I need to do like queries and pagination… :(
Wow. Cake makes it hard to create JOINs? That’s huge, actually. The hack you linked to doesn’t look too bad, but, arrgg. That’s unfortunate.
Yeah, to have to redefine relationships on the fly to trick the framework into doing the right thing was a major downer for me.
Also ran in to some issues with the convention/humanization of variable names (ie Person/people table). I had a species table. Since it’s spelled the same in plural and singular I had stuff in generated code like foreach($species as $species) {}, which popped out in every place where I used that model, so I defined and exception for the humanizer, yada yada yada but in the end I had to say screw it and refactored everything into ‘subjects’ which depleted my happythoughtmeter.
I mean, sure, it’s generated code. Sure, it’s cake 1.2x (which never seems to get out of RC) but well. The alternative would be to use 1.1 which is stable but has stuff like ‘you’re limited to one validator per model.’
More than a rant (although this is a rant) this is intended as mini-cautionary tale. Frameworks all look fantastic from their websites’ testimonials and feature list. However since one will be basically marrying whichever one choses I think it’s important to know the crap as well as the goods.
That said, I’m sure I’ll eventually find some gotchas with symfony as well but so far other than the slightly steeper learning curve I haven’t really found anything serious to complain about.
@Ariel Arjona
That is just one (possibly outdated) way to “force” joins in cake. There is a multitude of other ways to handle it. Linkable behavior works wonders… Another, easier option is outlined here: http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find
… and there are DB migrations in cake as well, which are quite nicely done. Not to mention the excellent console tools.
P.S. Granted this post is a bit old, and cake has matured quite a bit even over such a short period of time, but I figured it’d be nice to share more info for any of your readers. (Yes, I am biased towards cake) :)
Why not use regular mysql_query() for complex joins?
Comments on this entry are closed.