Bill Moseley wrote:
On Fri, Jan 8, 2010 at 6:55 AM, Tomas Doran <bobtf...@bobtfish.net
<mailto:bobtf...@bobtfish.net>> wrote:
$c->response->redirect($c->uri_for("/user/$user_id/blog/$blog_id/entry/list"));
Eww, don't do that.
You want
$c->response->redirect($c->uri_for_action('/user/blog/entry/list',
[$user_id, $blog_id]));
I agree that's the right approach, but not sure I see why the "Eww" in
this specific case. Can you explain?
Yes, c->uri_for("/user/$user_id/blog/$blog_id/entry/list") is hard
coding the URI, rather than asking the dispatcher to construct it for you.
This inevitably means that you'll have to change the code when you
refactor / change the URI layout later. Hard coding the URI paths to
your controllers in multiple controllers / templates is also of course
repeating yourself more than you need to be doing.
In fact, if possible, you probably want to be saying
$c->uri_for($self->action_for('foo'), \...@caps, @args);
because then you can reuse the controller code at a totally different
URI path without having to change any code at all.
Cheers
t0m
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/