[Catalyst] Use of uri_for with CaptureArgs

Bogdan Lucaciu bogdan at wiz.ro
Mon Feb 4 19:23:53 GMT 2008


On Monday 04 February 2008 14:09:25 Alan Hicks wrote:
> MyApp::Controller::Artist::Images
> sub images_setup : Chained('/artist/artist_setup') PathPart('images')
> CaptureArgs(1)  {}
> /artist/*/images/*
>
>  From within MyApp::Controller::Artist::Images uri_for($id, 'show')
> gives http://localhost/artist/images/*/show which does not take into
> account the artist id so do I have to build uri_for('/artist',
> $artist_id, 'images', $id, 'show') which appears cumbersome.

From the documentation of uri_for (perldoc Catalyst): 
$c->uri_for( $path, @args?, \%query_values? )

If the first element of @args is an arrayref it is treated as a list of 
captures to be passed to "uri_for_action"

I would do: 
$c->uri_for( $c->controller('Artist::Images').action_for('show') , 
[$artist_id, $image_id]);

this can be shortened by writing an action_uri sub in MyApp.pm: 
$c->action_uri( qw/Artist::Images show/, [$artist_id, $image_id]);
	
You can read more about uri_for in the calendar article:
http://catalyst.perl.org/calendar/2007/13

-- 
Bogdan Lucaciu
http://www.wiz.ro



More information about the Catalyst mailing list