Tuesday, March 30, 2010

Retrieving objects from the DB instead of arrays

I'm new to cakePHP and it seems like the only way to retrieve data
from the data source is as an array. I'm finding that I am using a lot
of code in my controller to prepare the arrays for display in the
view, when I would rather be able to send an object to the view and
get data from that object.

For example, if I had a person object, I could have an attribute that
was their birthdate and in the view I could easily get their age with
something like $person->getAge(). If I only have the person as an
array, then I have to do the calculating of the age before I can
display it.

Does this make sense? It is a simplistic example, but I can see myself
having to write a lot of code to manipulate arrays before the raw
database data is usable.

Thanks for your insights,
Jason

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

To unsubscribe, reply using "remove me" as the subject.

No comments: