A Glimpse Inside CakePHP 1.2 post

September 4th, 2007

One of my co-workers over at CDC (the mighty gwoo) gave a talk to the Orange Country PHP group about CakePHP 1.2 and some of the features that it contains. One of the more interesting items, well interesting to *me* anyway, is the addition of a convenience feature to "has and belongs to many" associations called "with". Stolen directly from gwoo's slides, here's an example of it: ~~~ array( ?className? => ?Tag?, ?with? => ?TaggedPost?, ) ); function beforeSave() { if(!empty($this->data[?Tag?])) { $this->TaggedPost->save($this->data[?Tag?]); } } } ?> ~~~ So what is the "with" parameter really for? It's nothing more than a convenience parameter that lets you apply a label to the name of your join table, so you don't have to call it by it's ugly name, in this case PostTags. Want to see it in action? ~~~ set(?tags?, $this->Post->TaggedPost->findAll()); } } ?> ~~~ It's little touches like that, unseen by a lot of developers, that makes CakPHP just a little bit easier to use with each passing day. You can download gwoo's slides here.