Let’s say we’ve got some calculated field in our find() method, something like SUM() or COUNT() or maybe AVG(). For the sake of example let’s
Month: September 2008
An interesting question came up on IRC today, which essentially boils down to: “How to save extra fields in the join table for HABTM models,
This is a simple hint, but hopefully will be useful to some… You might have noticed some examples where you have: $this->Profile->find(’all’, array(’fields’=>array(’SUM(Profile.votes) AS total_votes’)));
One example, that we often see, is something along the following lines in the controller: if($this->User->save($this->data)) { $this->Session->setFlash(… some stuff for the view …
One example, that we often see, is something along the following lines in the controller: if($this->User->save($this->data)) { $this->Session->setFlash(… some stuff for the view …
Here’s another trick with Set::merge()… Let’s say we’ve defined some basic validation rules in our Profile model, something like: var $validate = array (
This little trick will allow you toggle any field, for example ‘status’ which can be either 0 or 1… Add this little function to your
Update (9/16/2008): As some people pointed out it’s easier to use the h() method defined in basics.php of the core, it achieves the same basic
Let’s say you have a Posts controller, where you’ll need to paginate some posts in various actions. You might have some “generic settings” as the
Nice folks over at Packt Publishing asked me to a do a review of a book they’ve recently published, called “CakePHP Application Development“, by Ahsanul