[Catalyst] iterating ResultSet in controller vs. template

John Napiorkowski jjn1056 at yahoo.com
Tue Jun 19 18:47:29 GMT 2007


--- John Goulah <jgoulah at gmail.com> wrote:

> If I do something simple like this:
> 
>      my $myalums  = [
> $c->model('MyDB::Alumni')->search({}, { rows => 20
> })
> ] ;
> 
> and stash it:
>     $c->stash->{alumni} = $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 = $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.

--john

> 
> unless I dont return an anonymous reference like:
> 
>     my $myalums  =
> $c->model('MyDB::Alumni')->search({}, { rows => 20
> }) ;
> 
> then the while loop above works fine, but I dont get
> any output in the
> template.  I'd like to be able to use the iteraters,
> so what am I doing
> wrong here?


> 
> 
> Thanks!
> John
> > _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 



       
____________________________________________________________________________________
Got a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz 



More information about the Catalyst mailing list