[Catalyst] default template

Eden Cardim edencardim at gmail.com
Fri Dec 29 19:31:08 GMT 2006


On 12/29/06, 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?

No, there isn't. Catalyst only emits the response after all the
actions are dispatched. One way you can keep the end action from
running is by not having one. In your case, set up a Controller
without an end action just for authentication. In there, you can set
up Path actions so you don't have to rewrite all the URLs you've
already got in your code:

sub logout : Path('/user/logout'){
    my ($self, $c) = @_;
    $c->logout;
    $c->res->redirect($c->uri_for('/'));
}

-- 
Eden Cardim
Instituto Baiano de Biotecnologia
Núcleo de Biologia Computacional e Gestão de Informações Biotecnológicas
Laboratório de Bioinformática
--
"you seem to think that 'close enough' is close enough...
please learn to be 'literal' around programming."
merlyn - on irc.freenode.net#perl



More information about the Catalyst mailing list