[Catalyst] uri_for and Chained actions

J. Shirley jshirley at gmail.com
Wed Oct 10 19:42:52 GMT 2007

On 10/10/07, C=E9dric Bouvier <cbouvi at free.fr> wrote:
> Hello Catalysters,
> I just started playing with Chained Actions, and so far I have a setup
> like this:
>     /myapp/*
>     /myapp/*/update
>     /myapp/*/update_do
> 'update' and 'update_do' being implemented in MyApp::C::Foo::update and
> MyApp::C::Foo::update_do, respectively.
> Now, in the <form> that gets displayed when calling
> /myapp/foo/42/update, I'd like the "action" attribute to point to
> /myapp/foo/42/update_do. Unfortunately, if I write:
>     <form action=3D"[% Catalyst.uri_for('update_do') %]>
> I end up with the URI to /myapp/foo/update_do. I could use
> $c->req->uri and use it as a base for the relative URL 'update_do', but
> please someone tell me that there is a better way?
Chances are you are looking for something like:

[% Catalyst.uri_for( Catalyst.controller('Foo').action_for('update_do'), [
42 ] ) %]

The syntax breaks down like this:
uri_for( $action_object, $capture_array_ref, $arguments, $query_parameters )

$action_object is a blessed object that you can get from
$c->controller->action_for( ... )

$capture_array_ref is all the arguments that go into the CaptureArgs(...)
bits.  Make sure this is an array ref that you pass in, like "[ 42 ]".

$arguments are the arguments to pass to the action (you can leave this out,
it seems)

$query_parameters are the bit to append to the URI, like ?foo=3Dbar -- and =
takes care of proper escaping (and you can leave this out as well).

What gets returned is a blessed object that stringifies to the desired URI,
complete with $c->req->base as it should be.

This is the best way, although it is a bit verbose -- stay tuned for some
cleanup for this syntax in later releases.

Hope this helps,

-- =

J. Shirley :: jshirley at gmail.com :: Killing two stones with one bird...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071010/cbe92=

More information about the Catalyst mailing list