[Catalyst] using uri_for to parsing parameters

J. Shirley jshirley at gmail.com
Thu Mar 18 20:02:15 GMT 2010


On Thu, Mar 18, 2010 at 9:38 AM, nhyda <nhydanhyda at gmail.com> wrote:
> I don't know whether someone has asked it yet.
>
> here is my situation.
>
> I have an action "find" that take one argument of book id
> and I have another action author that chained to find
> so in practice I use /find/1/author to list all the authors of book 1.
>
> now I want to capture the book id use form but still use the action "find"
> and "author"
> so in action "form_do",
> I use
> $c->response->redirect($c->uri_for("/find/$book_id/author"));
>
> but I have learned that $c->uri_for($self->action_for('author')*** should be
> a better approach.
> so how do I parse the $book_id if I don't want to hard code the URL.
>
> Thank you very much.
>


If you are truly using Chained (as the Dispatch type) and it is a
CaptureArg, you would be able to use:
$c->uri_for_action('/find/author', [ $book_id ]);

The syntax is pretty simple:
$c->uri_for_action( '/action/path', [ @captures ], @arguments, { query
=> 'param' } );

This works if you are using Chained and CaptureArgs(...) and Args(...)
in your action definition.

-J



More information about the Catalyst mailing list