[Catalyst] proper flow control with $c->foward, in search of
bobtfish at bobtfish.net
Fri Jan 8 16:35:28 GMT 2010
Bill Moseley wrote:
> On Fri, Jan 8, 2010 at 6:55 AM, Tomas Doran <bobtfish at bobtfish.net
> <mailto:bobtfish at bobtfish.net>> wrote:
> Eww, don't do that.
> You want
> [$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.
More information about the Catalyst