Re: A table with average & total row
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 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 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 -~--~~~~--~~--~--~---
Re: A table with average & total row
On Tue, Dec 23, 2008 at 11:01 PM, mathie 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? > Ask yourself the question - are you just going to display it OR you will be doing something more (eg: save for a report) with it? Display only == View HTH Tarique -- = Cheesecake-Photoblog: http://cheesecake-photoblog.org PHP for E-Biz: http://sanisoft.com = --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: A table with average & total row
Depends. If you can do it in DB without performance loss, that's the best way. If not, view is good enough. I tend to do as much as possible in the database, because the damn thing is optimized to work with (large) sets of data. But in the end, if that's not an option for you, whatever gets the job done... :-) On Dec 23, 6:31 pm, mathie 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 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 -~--~~~~--~~--~--~---
A table with average & total row
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 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 -~--~~~~--~~--~--~---