Yves Räber wrote:
Hi,
Try this.

replace : [% FOR mandator = Catalyst.session.mandators %]
by :      [% WHILE (mandator = Catalyst.session.mandators.next) %]

Yves.


Thanks Yves, but I already had tried this. Doesn't work either. Given Guillermo's explanations, that's normal.

I've now tweaked Stephen's version to my gusto. FWIW, here's the code:

The login action:
------------------
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')))
    {
        my %mandators = ();
        foreach my $fields_dbic($c->model('MotsDB::Mandator')->all()) {
            $mandators{$fields_dbic->id} = $fields_dbic->name;
        }
        $c->session->{mandators} = \%mandators;

        $c->flash->{message} = 'Login successful.';
        $c->res->redirect($c->uri_for('/'));
        $c->detach();

    } else {
        $c->stash->{error} = 'Login failed.';
    }
}
------------------


And the template:
------------------
<br>
Active mandator:<br>
<br>
[% IF Catalyst.session.mandator.id %]
  [% Catalyst.session.mandator.id %]<br>
  [% Catalyst.session.mandator.name %]
  <p>
  <hr>
  <p>
[% END %]

[% IF Catalyst.session.mandators %]
  Other mandators:<br>
  <br>
  [% FOREACH id IN Catalyst.session.mandators.keys.sort %]
    [% IF id == Catalyst.session.mandator.id %] [% NEXT %] [% END %]
    <a href="[% Catalyst.uri_for("/mandator/select/$id") %]">[% id %]
    </a><br>[% Catalyst.session.mandators.$id %]
    <p>
  [% END %]
[% END %]
------------------


For now, I'm perfectly happy with that. Thanks again to everybody for the help and suggestions. Very appreciated!

Greetings
--Pierre

_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to