[Catalyst] Relative links
Matt S Trout
dbix-class at trout.me.uk
Thu Nov 10 01:33:33 CET 2005
On Wed, Nov 09, 2005 at 03:17:41PM -0800, Bill Moseley wrote:
> On Wed, Nov 09, 2005 at 09:22:26PM +0000, Matt S Trout wrote:
> > On Wed, Nov 09, 2005 at 01:02:08PM -0800, Bill Moseley wrote:
> > > I originally was creating a $c->stash->{myself} entry for
> > > self-referencing links in all my controllers. Seems like the only way
> > > since Catalyst can't really know what action is the "self".
> >
> > As of 5.49, you can access the Catalyst::Action object for the current action
> > via $c->action. Something like $c->action->attributes->{Path}[0] will work
> > for any Path or Regex action.
>
> Well, Catalys::Action will be useful.
>
> In my template (e.g. for creating my table heading links) I have been
> using:
>
> USE u = URL('', c.req.parameters );
>
> So I just changed to
>
> USE u = URL(myself, c.req.parameters );
>
> And then I can set "myself" as needed. Which can be:
>
> $c->stash->{myself} = $c->base . $c->action->reverse;
>
> Another useful Catalyst::Action is the ->namespace method. I already
> had this in my base class auto method:
>
> # Often want to link relative to the controller.
> if ( $c->req->action ) {
> my @segs = split(m!/!, $c->req->action );
> pop @segs;
> $c->stash->{controller} = join('/', '', @segs );
> }
>
> But can now be replaced by:
>
> $c->stash->{controller} = $c->action->namespace;
Bear in mind also that there's now a $c->namespace that keeps the *current
namespace* being executed in - so it changes on forward etc. $c->action
doesn't because it's the main action of the request rather than the current
namespace.
--
Matt S Trout Specialists in Perl consulting, web development, and
Technical Director UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list