Re: toArray was DB_DataObjects and generating search filters
| From: | Laszlo Hermann | Date: | Fri, 22 Apr 2005 07:00:40 +0000 |
| Subject: | Re: toArray was DB_DataObjects and generating search filters | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18909@lists.php.net to get a copy of this message | ||
Yes, it returns the object. This is not the nicest way to use in templates,
though :)
Just replace
> $list[] = $this;
with
$list[] = $this->toArray();
and you'll have the arrays in the list. The prettiest way would be
$list = $this->toTemplateArray(); (or call it as you like it)
and write that function toTemplateArray() to return $this, $this->toArray()
or anything you want to use it.
Laszlo
--- dude, my english really sucks
On 4/22/05, pear@electroteque.org <pear@electroteque.org> wrote:
>
> > I've added the following function to my DB_DataObject:
> >
> > function toArrayList ()
> > {
> > $list = array();
> > while ($this->fetch()) {
> > $list[] = $this;
> > }
> > return $list;
> > }
> >
> > This is pretty useful for me. In the program I just write
> >
> > $person = DB_DataObject::factory('person');
> > $query = "SELECT ... foo ... bar...";
> > $person->query($query);
> > $smartyRenderer->setAttribute('persons', $person->toArrayList());
> >
> > So first you build the dataobject, write the find / get / query, then
> > just call toArrayList() then you have a list of the DOs. This works for
> > very well for me; however, I would appreciate if the original
> > DB_DataObject would have this, written in a more professional way.
> >
> > Laszlo.
>
> Interesting , i've been tweeking it alot lately, should i add this, and
> then forward as a feature request ? Let me do some tests on it first, isnt
> $this returning the object though ?
>
> If you see my example, i want the key as the options value and the second
> column in the select statement as the select value
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>