[Catalyst] Multiple chaining to same action ...

Octavian Rasnita orasnita at gmail.com
Mon Feb 15 21:14:11 GMT 2010


From: "Kiffin Gish" <kiffin.gish at planet.nl>
> In my application, users are allowed to edit only their own settings
> like this:
>
> /account/id/client/settings/edit
>
> | /role/*/settings/edit | /auth (0)                       |
> |                       | -> /role/base (1)               |
> |                       | -> /role/settings/crud/base (0) |
> |                       | => /role/settings/crud/edit     |
>
> # Controller::Role
> sub base : Chained('/auth') PathPart('role') CaptureArgs(1) {
>    my ( $self, $c, $id ) = @_;
>
>    # Get the user if possible.
>    my $user = $c->model('DB::User')->find($id);
>
>    # Make sure that the user is indeed this user.
>    $c->detach('/error_403') unless $c->user->id == $id;
>
>    # Save the user in the stash.
>    $c->stash( user => $user );
> }

Why do you need this subroutine?
It should be reached only by the authenticated users, and if somebody 
reached here, you can just get his/her user id from $c->user->get('id') and 
you can get this information in the other subroutines also.

Octavian




More information about the Catalyst mailing list