[Catalyst] default end paths and forwarding
    Bill Moseley 
    moseley at hank.org
       
    Thu Dec 15 16:33:27 CET 2005
    
    
  
On Thu, Dec 15, 2005 at 09:59:04AM -0500, John Lifsey - Contractor - wrote:
> It may be that I'm going about this the wrong way, but I have my default 
> end setup to set
> stash->{template}||=$c->req->path
C::View::TT already does something like this:
    my $template = $c->stash->{template}
      || ( $c->request->match || $c->request->action ) . 
           $self->config->{TEMPLATE_EXTENSION};
> this works great for those tiny little actions that don't need entire 
> subs just to specify a template, but since it relies on path, breaks if 
> I forward to an action.
I had a similar problem when forwarding to an action in a different
controller namespace in that links (via c.uri_for ) were wrong --
they referred to the original action, not the forwarded action.
So, my solution was to do a subrequest instead of a forward.  Then it's
just like the forwarded action was the original action.
I use this in my app base class:
sub internal_redirect {
    my ( $c, $action, @args ) = @_;
    unless ( defined $action ) {
        $action = $c->action->namespace;
    } else {
        $action = join '/', $c->action->namespace, $action unless $action =~ m!^/!;
    }
    $c->res->body( $c->subreq( $action, @args ) );
    return;
}
And use $c->internal_redirect instead of $c->forward.
-- 
Bill Moseley
moseley at hank.org
    
    
More information about the Catalyst
mailing list