[Catalyst] default template

John Napiorkowski jjn1056 at yahoo.com
Fri Dec 29 19:26:17 GMT 2006


--- Octavian Rasnita <orasnita at gmail.com> wrote:

> Hi,
> 
> I often need to make external redirections like in
> the following case:
> 
> sub logout : Local {
> my ($self, $c) = @_;
> $c->logout;
> $c->res->redirect($c->uri_for("/"));
> }
> 
> When I access /user/logout for executing this
> subroutine, it prints the 
> following error:
> 
> Coldn't render template "file error - user/logout:
> not found"
> 
> So I need to add a template in the stash in this
> subroutine, even though I 
> don't want to use and print any template, but just
> do the redirect.
> 
> If I add before redirection:
> 
> $c->stash->{template} = "index.tt";
> 
> all works fine, but I guess something is not right
> in this code.
> 
> Isn't there a way to just stop everything and make
> the redirection, without 
> executing the end action?
> 
> If it is not a way, isn't there a way to specify a
> default template that's 
> used in these cases, for not needing to specify it
> manually every time?
> 
> I have seen that the order of the actions ran is:
> /auto
> /user/logout
> /end
> -> TranzactiiBursiere::View::TT->process
> 
> Thank you.
> 
> Octavian

I had a similar problem.  The key thing to know is
that using $c->response->redirect is just setting the
HTTP headers for you, it isn't telling Catalyst to
stop everything right there and then and process the
response.  So your default end action is trying to
process a template, but isn't finding one.  You need
to either manually detect the redirect request in your
end action and have it skip forwarding to the template
toolkit view or use something like the Renderview
action:

http://search.cpan.org/~mramberg/Catalyst-Action-RenderView-0.04/lib/Catalyst/Action/RenderView.pm

which will do that for you.

If you look at the source code for that action you
will gain a better understanding.

--John

> 
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list