[Catalyst] how to get controller path

Peter Karman peter at peknet.com
Tue Nov 20 14:30:58 GMT 2007



On 11/20/2007 06:52 AM, Matt S Trout wrote:
> On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote:
>> Hi,
>> Need a bit of help.
>> 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);
> 

That assumes you know which Controller to start with.

I've had this same issue recently. The problems IME are case and attributes.
E.g., URIs are all lc() but the corresponding Controller/Action could be any case.

 /foo/bar

might correspond to:

 MyApp::Controller::Foo::Bar->default()

or

 MyApp::Controller::FOO->bar()

or

 MyApp::Controller::foo->BAR()

etc. You have no way of knowing from just a URI, and in my case, that was what
I had to go on in my template. The Catalyst::Dispatcher seems to be the correct
place to interrogate the action map for any given URL, maybe with
get_action_by_path().

Or am I way off base?

-- 
Peter Karman  .  peter at peknet.com  .  http://peknet.com/




More information about the Catalyst mailing list