If you are already pulling all the data back in your controller ($foo
= $this->Model->findAll())
...then it makes sense to do the calculation in the controller
(count($foo)) as this avoids an extra query.
That said, fat models is the way to go. In this case, I would add a
count() method to the model and use that for those times I'm not
fetching back all the data in the controller.
You could even do something like this:
function count($data = null) {
if ($data == null) {
// do the sql query that gets you the count
}
else {
return count($data);
}
}
and pass the $data in your controller when you have it
---
On Feb 3, 3:01 am, chad <[EMAIL PROTECTED]> wrote:
> Neil - you're right on, put that logic in the model, that way it can
> be reused if you need it elsewhere and changed in one place.
>
> On Feb 2, 9:53 am, "Dr. Tarique Sani" <[EMAIL PROTECTED]> wrote:
>
> > On Feb 2, 2008 9:35 PM, Neil <[EMAIL PROTECTED]> wrote:
>
> > > I want to count some data from my database and then display the amount
> > > in my view.
> > > From reading the manual I would think the proper MVC was would be to
> > > make a function in my Model that counts the records in the field and
> > > then use the controller to send the result of that Model function to
> > > my view.
>
> > FWIW - This is what I would do - thumbrule is Fat Models - thin controllers
>
> > 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 "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---