Friday, January 30, 2009

[Newbie] Data container classes and pagination?

I think I'm missing something.....

When I fetch with the pagination function, it returns an array of
associative arrays rather than an array of objects based on my
model.

Questions...

1) Is the model class supposed to be used as a data container where
you can extend it with custom accessor methods etc. Or is it more of
for abstraction of database operations?

2) Is there an elegant mechanism in Cake (or PHP for that matter) that
will take the result set (array) and convert it into an object (either
based on it's model class or an entirely separate data container
class)?

3) Let's take an overly simplified example. I want a derived value
that multiple controllers/views will need to use. I don't want to
repeat the business logic in each controller and I'd preferably like
it in 1 place. Where does one do it? Here's a straw man that I hope
someone can use to help me understand this better.....

Option 1. Custom accessor method in the model or some other data
container....
ex. $fullname = $person->fullName();
This is ideal because it's a built into a data object. But cake
doesn't return objects.

Option 2. Static method in the model.
ex. $fullname = person::fullName($row);
I can live with this and my guess is that the model is more of a
toolbelt than a container

Option 3. Shared function (where should I put things like these?)
ex. $fullname = fullNameFromPersonRow($row);

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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: