[Catalyst] iterating twice over the same resultset in the template?

Dylan Vanderhoof DylanV at semaphore.com
Wed Jan 3 19:47:50 GMT 2007


[% items.reset() %]

> -----Original Message-----
> From: Fernan Aguero [mailto:fernan at iib.unsam.edu.ar] 
> Sent: Wednesday, January 03, 2007 11:44 AM
> To: Catalyst
> Subject: [Catalyst] iterating twice over the same resultset 
> in the template?
> 
> 
> [ or perhaps 'is it possible to clone a resultset?' ]
> 
> Hi!
> 
> I'm building a form whose elements are items taken from the
> db.  And I need these items to show up in different elements
> (fieldsets) of the form. More or less something like this:
> 
> With items similar to:
>  'checkbox' - Item 1
>  'checkbox' - Item 2
>  'checkbox' - Item 3
> 
> with parts that belong to:
>  'checkbox' - Item 1
>  'checkbox' - Item 2
>  'checkbox' - Item 3
> 
> 
> In my controller:
> my $rs = $model->search( ... );
> $c->stash->{items} = $rs;
> 
> In my template (TT):
> <form ...>
> <fieldset>
> [% WHILE ( it = items.next() ) -%]
> <input ... > [% it.name -%]
> [% END -%]
> </fieldset>
> 
> <fieldset>
> [% WHILE ( it = items.next() ) -%]
> <input ... > [% it.name -%]
> [% END -%]
> </fieldset>
> </form>
> 
> The problem is that the resultset is empty when I try to
> iterate over it the second time. 
> 
> So far the only way I've found to make this work is
> to do N separate searches, fill N stash elements, et cetera 
> 
> $rs1 = $model->search( ... ); $c->stash->{rs1} = $rs1;
> $rs2 = $model->search( ... ); $c->stash->{rs2} = $rs2;
> ...
> 
> [% WHILE ( it = rs1.next() ) -%] ...
> [% WHILE ( it = rs2.next() ) -%] ...
> 
> Is there any other way to do this? Is it possible to clone a
> resultset?
> 
> Thanks,
> 
> Fernan
> 
> 
> _______________________________________________
> 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/
> 



More information about the Catalyst mailing list