CakePHP Headaches

So I’ve started working on a little content app for the sites here and thought it would be a good sized project for a trial run of a few things including the CakePHP rails-like MVC framework written in PHP.

A few places I’ve stumbled and broken my toe so far…

Queries are cached by default

This was my first noob stumbling block. You do a findByName on an object and see it isn’t found so you add it. Then later on in the loop you happen to look up that same item but the result is still that it doesn’t exist. Did your save fail without warning? Nope, the findByName results were cached and didn’t get updated after the insert. The quick and dirty solution – adding var $cacheQueries = false; to appropriate models.

Order of array data matters in hasAndBelongsToMany relationships

This one I would have never figured out had it not been for stumbling over it while looking up some other problems I was having with my HABTM cases. Bug, intentional, I don’t know, but it certainly wasn’t something I was expecting.

Creating new associated objects

This is more of a gripe then a problem, but if as a framework you’re going to provide lots of core tools to manage relations like hasOne or HABTM then why not provide some utilities to deal with both new primary objects and new associated objects during a save of the primary object? Seems to me (and to some others judging by the topic of questions I have come across) that the need to generate related objects on the fly is quite common—especially when you move away from doing all of your content management via scaffold based web forms.

Hard to grok errors from the framework

… like Notice: Undefined index: id in /ServerRoot/wowt/public_html/cake/libs/model/model_php5.php on line 914

Sure, I was able to trace it back and figure out where things were going wrong after upping the debug level on my app and adding a few other print_f calls, but something a bit more informative might be helpful and save some time.

I certainly realize that the framework is still in active development, that and I’m coming at things head one and coding without much background with the existing docs and other resources (so far the mailing list seems to be the best source of information). Many of these headaches would go away with time (either as a result of work of core devs or my own familiarity), but I thought I needed to make a record of them for future reference.

As for the app I’m building—you’ll know more soon-ish.

P.S. RSS is giving me as many if not more headaches. Maybe I’ll cover that later.

Comments Temporarily(?) Removed