[Catalyst] how to get controller path

Matt S Trout dbix-class at trout.me.uk
Thu Nov 22 14:34:07 GMT 2007

On Wed, Nov 21, 2007 at 11:31:40AM +0530, Alok Sharma wrote:
> On Tuesday 20 November 2007 18:22:54 Matt S Trout wrote:
> > On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote:
> > > Given a path we have ways to get the uri using the method uri_for(path).
> > > Is there a  possible way to get the controller path given the uri so I am
> > > able to do some thing like this
> > > 	$c->res->redirect(uri); $c->forward(controller_path(uri));
> >
> > Why can't you start off with a controller action?
> >
> > my $action = $c->controller('Foo')->action_for('bar'); #
> > Controller::Foo->bar
> >
> > $c->res->redirect($c->uri_for($action));
> > $c->forward($action->reverse);
> I was trying to write a module where the user asks for a particular URI but 
> for certain reasons ( say session expired or not yet logged etc. ) has to be 
> authenticated again and then user will be automatically redirected to the 
> requested page,in a way furnishing something before actual request is 
> processed. 
> For this I saved the URI requested ( say as $path ) as a session variable, 
> redirected to the authentication page ( say to the standard login page ). But 
> the issue was to redirect to the page requested by the user for which I got 
> back the URI path from the session variable, till here all fine. But without 
> knowing the action for that URI name I cant forward to it. That is where I 
> needed something like 		$c->forward(controller_path(uri));
> Or is there another approach to this problem.

I just pop up the login form on the requested page - i.e. $c->detach('/login')
or so.

Then I handle the login in the same place (Root::auto or an early Chained part
depending on the app) as I'd normally check permissions, so if the login
succeeds the basic Catalyst dispatch already done executes the right code

The only trick to this is calling the login form fields __login__username or
similar so that they're guaranteed not to clash with anything else.

      Matt S Trout       Catalyst and DBIx::Class consulting and support -
   Technical Director      http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Christmas fun in collectable card game form -

More information about the Catalyst mailing list