[Catalyst] Question about Chained Controller

woosley. xu. redicaps at gmail.com
Mon Nov 15 02:03:36 GMT 2010


Hi All,
     I am quite a beginner for Catalyst. When I used Chained Controller to
handle  some permission pages, I met a problem

First I use this piece of code to make sure that a user is logged in, if
not, the use will be forward to the login page, and I assume after login, it
will return back to the original page


 sub base : Chained('/') : PathPart('user') : CaptureArgs(0) {
    my ($self, $c) =3D @_;
    if (!$c->user_exists) {
        $c->flash->{'message'} =3D "You need to login to view this page";
        $c->forward('login');
      }
    $c->stash->{'resultset'} =3D $c->model('DB::User');
 }


So in the other actions, I don't need to check the user is logged in or not


  sub get : Chained('base') : PathPart("") : CaptureArgs('1') {
    my ($self, $c, $id) =3D @_;

    if ($c->user->id =3D=3D $id) {
    ...........
  }


But it did not work out as I thought so, when I try to access  some page,
eg. /user/$id/view
I got a error

Caught exception in SEA::Controller::User->get "Can't call method "id"
on an undefined value


What is the problem with this code?


-- =

Woosley.Xu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101115/0edc5=
38f/attachment.htm


More information about the Catalyst mailing list