CakePHP

This was written haphazardly in a forum, please take it as-is (or as a rant of some kind)!
Ok, so before I started using cake I went in to the #cakephp channel on freenode and asked:

“yes, but what about when my application gets really complicated?”
“don’t worry, it’s totally flexible”
“I love cake”
“etc..”

I was still skeptical, but we had a small project coming up at work and a fair bit of time to do it in. Cake fit the bill perfectly. A success!

We’re just coming to the end of a project say, 2 or 3 times the magnitude of that first one. I’ve now had time to form some real solid opinion about CakePHP.

CakePHP has some good points and bad points. One of the nice things about cake is it throws you into the MVC (Model/View/Controller) pattern way of thinking, and without having to learn ruby or something weird like that. The code I’ve been working on has been a lot easier to code because of this nice seperation..although in some cases it has taken slightly longer.

For example, a simple login form can take slightly longer to make as you have to create an login action member to your controller (a function), and then the view (template) and then the model (I’ll get on to that) rather than one quick bodge.

Having said that, I really like it so that gets thumbs up!

Now for why it isn’t quite as good as people say (or at least why I think it’s a bit shit). Models.

So instead of just doing $data = mysql_fetch_assoc($query, $handle) or whatever, you use cake’s ‘model’ abstraction layer, so you’d do something like $this->Model->fetch($data) or something..I don’t remember exactly.

There are a few problems with this:

First and foremost, you need to learn quite a lot, and it’s poorly documented for when you have many to many relationships etc..
CakePHP is poorly documented anyway!
It’s silly, because like a lot of these ‘bright’ ideas, it ends up being wayy more complex than just throwing in a simple (or complex) query.

Yes, for quite simple projects, you (me) could probably get away with using Cake’s modeling bit. However, for complex stuff, you’ll find you’re using $this->Model->query();

That brings me on to why I might continue to use cake in the future…

It’s nicely flexible, next time, I won’t bother trying to use any of Cake’s modeling features to get my data. I’ll just use normal queries..we found we were doing that by the end of the project anyway. I think for beginners, Cake’s modeling language *might* be easier to learn than SQL, but I know SQL and that works well for me…and you don’t have to be messy with it either.

Second thing I really like about cake is that a lot of stuff can be done for you by it’s helper library, for example, $html->dropdown() (or something to that effect) adds a drop down list from an array in your view.

What would be really cool is a cakephp without all the chaff of the model stuff…some kind of cakephp for people who know and love SQL perhaps?

Well, that’s my take on it. If you’re thinking about using it, first I’d suggest you think very hard. Cake is still in it’s infancy, and you’ll find quite a bit isn’t documented at all (I had to speaker to the developer to get some answers). Secondly, it might be easier/better..especially if it’s a one person project to write your own framework based around all this. I’m talking about a very ‘lite’ framework, perhaps just a few files, no more than 200 lines of code?

I’ve had a bit of experience writing my own framework, first one I tried sucked, second one worked really well and I’m now in the process of making a third simply for knocking up sites really quickly. How often do you find yourself coding the same things?

Happy baking!

6 thoughts on “CakePHP

  1. Hi John,

    Having to set up models can seem like overkill if you’re knocking up a quick and simple website, but they become really useful when it comes to things like establishing data validation rules or setting up relationships between database tables.

    I often use something like a findAll() statement to get my data, using the $sql, $order and $limit parameters to fine-tune the query where necessary, but I do hear people saying they prefer doing a query() because they’re more comfortable with the standard SQL syntax.

    I agree about the documentation. Unfortunately there’s no real alternative at the moment to scrabbling around on the documentation site, wiki, IRC channel and Bakery to find what you need. Hopefully the new Bakery site will become popular very quickly, and help to get that information centralised!

  2. I’ve been searching the web far and wide for a php framework for weeks. I tried almost all of them (most fall flat on their face because of lack of documentation). However, the cake documentation is quite good compared to many that are out there. If you use the documentation in conjuction with the API most things become clear. However, the reason I landed hear is because I did a search “cakephp many-to-many”. I still searhing for how to do it.

  3. John,

    I think there are some things to work through when getting used to Cake, but with a little bit of work and some head-scratching I haven’t come across anything yet that has stopped me.

    Even though it’s a bad practice, I agree… Cake really isn’t a hindrance because you can always ignore the framework and do things your own way. Obviously, that can cause problems long term… but it helps when you just can’t figure something out and are tired of trying (which hasn’t happened to me yet).

    Regardless, what Cake does provide is increased efficiency, increased standardization (important when working in groups), maintainable code, and a huge community of people interested and willing to help.

    IMHO, it just works.

    – Dustin Weber

  4. The single reason most open source projects like cake choose to “touch” the simplicity of SQL is that there is no ANSI SQL anywhere. The only way to make a framework’s code readable (and workable) by everyone is to somehow get rid of SQL.

    The problem with this method is that instead of learning SQL flavors you must learn SQL workarounds. However till someone big comes up with a widely acceptable SQL wrapper we have no choice than to hide sql.

  5. I like your analysis and totally agree on the fact that Cake is not that well documented. A framework like CodeIgniter has a good documentation, but doesn’t allow an as easy MVC model as Cake does.

    I also found your site by searching for many-to-many relationships in CakePHP. Hope I’ll find something usefull.

    regards

  6. Its totally true CakePHP doesn’t have a real good documentation. But i must say it keeps getting better so i am looking forward to next releases of CakePHP. I like to browse around in the api.cakephp.org directory 🙂

    take care,
    Michelle

Leave a Reply

Your email address will not be published. Required fields are marked *