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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to