Not sure if this is the right place, though it would have helped me understand how to use Chained actions more easily as I forget to refer to the Advent Calendar.

Alan Hicks wrote:
Bogdan Lucaciu wrote:
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


Thanks,
Thought I'd missed something obvious.

_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

--- Chained.pm.orig	Mon Feb 18 17:25:58 2008
+++ Chained.pm	Mon Feb 18 19:31:14 2008
@@ -463,6 +463,37 @@
   '-----------------------+------------------------------'
   ...
 
+=head2 Referring to the uri
+
+Generating and using URI's from anywhere within your app can be made
+easier by adding the following two routines to your main application
+class (e.g. MyApp.pm).
+
+  sub action_uri {
+      my ($c, $controller, $action, @params) = @_;
+      return $c->uri_for($c->controller($controller)->action_for($action), @params);
+  }
+
+  sub redirect_to_action {
+      my ($c, $controller, $action, @params) [EMAIL PROTECTED];
+      $c->response->redirect($c->uri_for($c->controller($controller)->action_for($action), @params));
+      $c->detach;
+    }
+
+A URI can be used from anywhere within your application using the
+following snippets
+
+    $c->redirect_to_action('Greeting','world', [23, 12]);
+
+    my $uri = $c->action_for('Foo::Bar','baz', [5]);
+
+And just as easily from any Template
+
+    <a href="[% c.action_uri('Greeting','world', [23, 12]) %]">Hello!</a>
+
+    <a href="[% c.action_uri('Foo::Bar','baz', [5]) %]">BAZ!</a>
+
+
 Here's a more detailed specification of the attributes belonging to 
 C<:Chained>:
 
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to