[Catalyst] $c->uri_for with no args

Bill Moseley moseley at hank.org
Wed Nov 30 00:26:59 CET 2005


[
I'm posting this again.  It just seems a bit odd that uri_for with no
args to append a trailing slash.  I'm not sure if that would ever be a
problem, but it would be good to document the way it works.

]


       $c->uri_for($path,[@args])
           Merges path with $c->request->base for absolute uri's and
           with $c->request->match for relative uri's, then returns a
           normalized URI object. If any args are passed, they are
           added at the end of the path.

Doesn't define what happens if nothing is passed in.  It's basically
c.req.match, but with a trailing slash.

I'm not so sure why one would use uri_for without an argument, but the
trailing slash seems somewhat inconsistent (compared to base + match).



I suppose one might use it to have a link back to the same action
with params stripped:

    action /foo/bar/baz
    request: /foo/bar/baz?limit=blue&date=today

    <a href="[% c.uri_for('12') %]">view baz 12</a>  /foo/bar/baz/12

    <a href="[% c.uri_for %]">list all</a>   /foo/bar/baz



BTW -- I added my own uri_*() methods.

For example, I have $c->uri_action which is relative to the name
space, not the match.

So if in the 'view' action one could show the 'detail' action like:

    $c->uri_action('detail');  # run 'detail' action in current name space

The other reason I have my own uri_* methods is because they are based
on items in the stash (e.g. loaded from $c->action->namespace) so in
the event I need to forward to another action (from 'edit' to 'list')
I can update the stash and links will be relative to the forwarded
action, not relative to the originally matched action.

I'm not sure if this is actually useful to me or not, yet... ;)





-- 
Bill Moseley
moseley at hank.org


_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst




More information about the Catalyst mailing list