Wednesday, March 31, 2010

Re: Retrieving objects from the DB instead of arrays

After your $model->find(), you can try the Set::map() function on the
resulting array (see: http://book.cakephp.org/view/676/map). I
haven't personally used it myself, but the documentation indicates
"Basically, the map function turns array items into initialized class
objects."

On Mar 30, 8:31 pm, paws_galuten <jason.galu...@gmail.com> wrote:
> 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: