[Catalyst] storing a list of items into the session
Yves Räber
yraber at mailup.net
Mon Mar 24 06:17:19 GMT 2008
Hi,
Try this.
replace : [% FOR mandator = Catalyst.session.mandators %]
by : [% WHILE (mandator = Catalyst.session.mandators.next) %]
Yves.
On Sun, 2008-03-23 at 17:52 +0100, Pierre Moret wrote:
> Hi,
>
> I'm fairly new to Catalyst, so please excuse me if my questions are a
> bit... hmmm... basic.
>
> My app is using the authentication and authorization features as
> described in Jonathan Rockway's book. So far so good. Now, I want the
> login procedure to load a list of items (I call them 'mandators')
> into
> the session data so that the list can be used in every template once
> the
> user has logged in. Loading one single item works well, but storing
> the
> whole list doesn't. Right now, I'm quite lost...
>
> Here's my login function (from the Root.pm file):
> ---------------
> sub login : Global Form {
> my ($self, $c) = @_;
> my $form = $self->formbuilder;
>
> return unless $form->submitted && $form->validate;
>
> if ($c->login($form->field('username'),
> $form->field('password')))
> {
> $c->session->{mandator} = $c->model('MotsDB::Mandator')->find();
> $c->session->{mandators} = $c->model('MotsDB::Mandator');
>
> $c->flash->{message} = 'Login successful.';
> $c->res->redirect($c->uri_for('/'));
> $c->detach();
>
> } else {
> $c->stash->{error} = 'Login failed.';
> }
> }
> ---------------
>
>
> And here's the template:
>
> ---------------
> <!-- BEGIN site/right_col -->
> [% IF Catalyst.session.mandator %]
> [% Catalyst.session.mandator.code %]<br>
> [% Catalyst.session.mandator.name %]<br>
> [% END %]
>
> [% IF Catalyst.session.mandators %]
> [% FOR mandator = Catalyst.session.mandators %]
> - [% mandator.code %]: [% mandator.name %]<br>
> [% END %]
> [% END %]
> <!-- END site/right_col -->
> ---------------
>
>
> The first part of the template correctly displays the first mandator
> stored in the table. But the FOR loop doesn't work: it goes once
> through, displays nothing and finishes.
>
> I'm probably missing something very basic, but I really can't figure it
> out... Would appreciate some hints! ;-)
>
> Greets
> --Pierre
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
More information about the Catalyst
mailing list