[Catalyst] iterating ResultSet in controller vs. template

John Goulah jgoulah at gmail.com
Tue Jun 19 19:16:40 GMT 2007


On 6/19/07, John Napiorkowski <jjn1056 at yahoo.com> wrote:
>
>
> --- John Goulah <jgoulah at gmail.com> wrote:
>
> > If I do something simple like this:
> >
> >      my $myalums  =3D [
> > $c->model('MyDB::Alumni')->search({}, { rows =3D> 20
> > })
> > ] ;
> >
> > and stash it:
> >     $c->stash->{alumni} =3D $myalums;
> >
> > I am able to iterate in the template like:
> >
> >    [% FOREACH alum IN alumni -%]
> >        id: [% alum.alumni_id %]  <br />
> >    [% END -%]
> >
> >
> > But if I try to iterate this in the controller, I
> > cannot do something like:
> >
> >     while (my $alum =3D $myalums->next) {
> >         $c->log->debug("id: ". $alum->alumni_id);
> >     }
>
> Because ->next isn't a method on an array reference.
> You could try derefing via @$myalumns.



I have tried a few things here.  I can get this to work:


    for my $element (@{$myalums}) {
        $c->log->debug("alum:". $element->alumni_id);
    }


but not :

    while (my $alum =3D @{$myalums}->next) {
        $c->log->debug("id: ". $alum->alumni_id);
    }

In this case I get:

Can't call method "next" without a package or object reference



I'm assuming I'm just doing something obviously wrong here?

Thanks!
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070619/ce1aa=
952/attachment-0001.htm


More information about the Catalyst mailing list