Ok, thank you for this code.
I haven't seen very many explanations about RenderView, so I didn't
understand how it works.
So I have used only RenderView until now, but not very smart, something
like:
sub end : ActionClass('RenderView') {
my ($self, $c) = @_;
$c->forward($c->view('TT'));
}
So it was just like a common sub : Private action.
Octavian
----- Original Message -----
From: "Jonathan Rockway" <[EMAIL PROTECTED]>
To: "The elegant MVC web framework" <[email protected]>
Sent: Friday, December 29, 2006 10:20 PM
Subject: Re: [Catalyst] default template
Octavian Rasnita 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("/"));
}
How about $c->detach() after the redirect?
BTW, I notice a common theme in your posts -- being burned by your
poorly-designed custom global end action. Please switch to RenderView
and avoid 90% of your problems :)
Since the code in RenderView is so small, I'm going to paste it here and
tell you why each line there is important. ## comments are my notes
sub execute {
my $self = shift; ## setup
my ($controller, $c ) = @_;
$self->NEXT::execute( @_ ); ## run everything in the actual end
## action first
## dump requested (by setting ?dump_info=1 in the URL)?
## if so, die so we get the debug screen
if ($c->debug && $c->req->params->{dump_info}) {
die "forced debug"
}
## no content type set? use text/html so that the browser doesn't
## choke
if(! $c->response->content_type ) {
$c->response->content_type( 'text/html; charset=utf-8' );
}
## client doesn't want body? don't render it!
return 1 if $c->req->method eq 'HEAD';
## custom body set in an action? send that instead
return 1 if length( $c->response->body );
## errors and no template to show them with? let Catalyst handleit
return 1 if scalar @{ $c->error } && !$c->stash->{template};
## redirect? don't render the template, just redirect!
return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
## get the view
my $view=$c->view()
|| die "Catalyst::Action::RenderView could not find a view to".
" forward to.\n";
## and forward to it
$c->forward( $view );
};
Pretty nice, eh? You can learn a lot by reading the fine source code.
Regards,
Jonathan Rockway
--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/