Thanks for your help guys :-)
On May 24, 7:34 pm, mark_story <mark.st...@gmail.com> wrote: > You can still do this with models as well. Using read(), create(), > and set() your model methods can access the 'active record' and > manipulate it. so for example > > $this->Apple->id = 1; > $this->Apple->read() > if ($this->Apple->isRed()) { > //do something > > } > > And your isRed method could look like > > function isRed($color = null) { > if (!$color && isset($this->data['Apple']['red'])) { > $color = $this->data['Apple']['color']; > } > return $colour == 'red'; > > } > > -Mark > > On May 23, 9:59 am, jakobjp <m...@jakobjp.net> wrote: > > > > > I've read a few discussions about CakePHP returning objects vs. > > arrays, and this is NOT intended to be such. I just have a question, > > related to it: > > > I used to have (i.e. "before CakePHP") objects like this: > > > class Apple { > > var $color; > > var $sweet; > > function __construct($id = false) { > > if ($id) $this->load($id); > > return $this; > > } > > function load($id) { > > ... do something to load apple with `id` = $id from db ... > > } > > function isRed() { > > if ($this->color == 'red') return true; > > else return false; > > } > > > } > > > In my code I would then often work like this: > > > $apple = new Apple(123); > > if ($apple->isRed()) echo 'Apple is red"; > > else echo 'Apple is not red'; > > > Now my question: > > Where would a function like isRed() be located in the the CakePHP-way? > > > Since in Cake I don't have an object to call a model's method on, I am > > not sure how to go about this... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---