I would tend to agree with the prior comments that you do things like
counting at the database, so you would put things like counts and
totals in your model, or in the controller logic by adding the
appropriate calls.
You can add a calculated field like $amount in your model's afterFind
method and it works really nicely if you don't need to save it in the
DB.
function afterFind($results) {
// Create an amount pseudofield using
foreach ($results as $key => $val) {
if (isset($val['Invoice']['price']) && isset($val
['Invoice']['quantity'])) {
$results[$key]['Invoice']['amount'] = $val['Invoice']
['price'] * $val['Invoice']['quantity']
}
}
return $results;
}
On Dec 23, 9:31 am, mathie <[email protected]> wrote:
> Hello,
>
> This is a design question on MVC separation. Say I need to display a
> table with many rows, then a total and an average row. Should the
> calculation of this total/average be done in the view (in the loop) or
> in the controller (after getting the rows from DB)?
>
> A related question. For an invoice: $amount = $price * $quantity;
> Could that be in the view or not?
>
> Basically I guess my question: what is considered view logic?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---