Not quite sure if "instance methods" is the right term for what you're asking for, but anyway.
Look into Model::read() and Model::set(); A Model::find() will only return the data, it will not persist it in the model instance. set() is used to, well, set data inside the model, i.e. it will be persisted in Model::$data. In a model function you can then access $this->data. Model::read() will find a record by id and automatically set() it. Actually though, Cake is less object oriented than Rails. It's more Cake-like to expect your data to be in an array that you feed into functions, rather than data being persisted in the model instance. On 9 Oct 2008, at 16:29, cbankier wrote: > > Hi, > I'm new to Cake, but have used rails quite a bit as well as Java > frameworks etc. > > Is it possible for a model to have instance methods? eg have behaviour > that depends on the objects state - the fundamental concept of > objects. > > Here is an example of something I might do in rails/Java. The syntax > is almost certainly wrong for cake, but hopefully you can see what I'm > trying do to and hopefully explain the cake way of achieving this. > > Secondly in this example the model is aware if it's associations. Is > that possible/recommended in Cake? > > class Order extends AppModel { > var $hasMany = 'Product'; > > function getTotal(){ > $total = 0; > foreach($this->Product->find('all') as $product): > $total += $product->price; > endforeach; > > return $total; > } > > } > > and then a controller might do: > > $order = $this->Order->findById(5); > $orderTotal = $order->getTotal(); > > Any help appreciated. > Cheers, > Colin. > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---