[Catalyst] Generate a URL for a given action
John Napiorkowski
jjn1056 at yahoo.com
Thu Aug 31 19:37:20 CEST 2006
That was the bit the did the trick. I guess I didn't follow the documentation chain up high enough (I stopped at catalyst::component). However one tricky part, if the action you name is part of a chain you need to make sure you submit the captures arrayref, otherwise $c->uri_for doesn't return anything. So for my example you could do:
my $view_action_link = $c->uri_for( $c->controller->action_for('view'), $c->request->captures );
$c->response->redirect( $view_action_link );
And this does exactly what I was looking for! Thanks!
Just another note, you can skip passing the controller method a name if the action you are looking for is in the same package, which makes this even more generic.
This really helps to make your code more generic and simplified. I just showed this to a group of consultants I'm working with on a cgi based application and I got them all drooling with envy :)
--john
----- Original Message ----
From: Bogdan Lucaciu <bogdan at wiz.ro>
To: John Napiorkowski <jjn1056 at yahoo.com>; The elegant MVC web framework <catalyst at lists.rawmode.org>
Sent: Thursday, August 31, 2006 12:13:40 PM
Subject: Re: [Catalyst] Generate a URL for a given action
On Thu, 2006-08-31 at 08:28 -0700, John Napiorkowski wrote:
> because I already have the title in the database resultset and I know
> right now this controller is rooted to the start of the web server.
> What I would really like to know is if there is a programmatic way to
> get this stuff. I know I can get the capture string via:
> $c->request->captures->[$level]. Ideally I wouldn't have to hard code
> so much controller specific stuff here.
>
try
$c->uri_for($c->controller('Foo::Bar')->action_for('action_name'));
(action_for documented in Catalyst::Base)
--
Bogdan Lucaciu <bogdan at wiz.ro>
More information about the Catalyst
mailing list