zen of coding

Automagical selects or checkboxes

A quick example of some automagic goodness… Let’s say we need to to build an “add Post” form and allow the user to pick some tags for the Post. In our Posts controller’s add() action, we’d probably do something like this: $this->set(’tags’, $this->Post->Tag->find(’list’, array(’fields’=>array(’Tag.tag’)))); Then in the view, while building[…]

Read More »

Filtering results returned by Containable behavior

First of all, let me warn you that what I’m describing here is more or less a hack and is not the most efficient way of handling such things, especially if you are dealing with large volumes of data. It is really here for educational purposes and as food for[…]

Read More »

HABTM and JOIN trickery with CakePHP

Update (10/7/2009)… this functionality has been rolled into Habtamable behavior An interesting question came up on IRC today… If I have Post HABTM Tag, how do I select only Posts that have Tags “new” AND “cakephp”? A seemingly simple problem, actually required a pretty tricky solution. I do have to[…]

Read More »

'fields', 'conditions' and associated models in CakePHP 1.2

Sometimes you see code that tries to do something like this: $this->Company->find(’all’, array(’conditions’ =>array(’Profile.name’=>’test’),                                             ‘fields’=>array(’Profile.id, Profile.name’))) Of course most of the time you’ll hear: “Well, this doesn’t work!”[…]

Read More »

Practical use of saveAll() (part 2, notes and tips)

In part 1, I explained how to use saveAll() in order to save multiple models at the same time, if you haven’t had a chance to read that post please do so before starting on this one. 1. Saving multiple records for the same model. Using our models from the[…]

Read More »
%d bloggers like this: