| Jifty documentation | Contained in the Jifty distribution. |
Jifty::Action::Redirect - Redirect the browser
Jifty->web->new_action(
class => 'Redirect',
arguments => {
url => '/my/other/page',
},
)->run;
Given a URL, this action forces Jifty to perform a redirect to that URL after processing the rest of the request.
By default, redirect actions happen as late as possible in the run order. Defaults the order in Jifty::Action to be 100 so it runs later than most actions.
The only argument to redirect is the url to redirect to.
If the other actions in the request have been a success so far,
redirects to the provided url. The redirect preserves all of the
Jifty::Results for this action, in case the destination page wishes
to inspect them.
Jifty::Action, next_page in Jifty::Web, force_redirect in Jity::Web
Jifty is Copyright 2005-2010 Best Practical Solutions, LLC. Jifty is distributed under the same terms as Perl itself.
| Jifty documentation | Contained in the Jifty distribution. |
use warnings; use strict;
package Jifty::Action::Redirect; use base qw/Jifty::Action/;
sub new { my $class = shift; my $self = $class->SUPER::new(@_); # XXX TODO This is wrong -- it should be -1 or some equivilent, so # it is sorted last all the time. $self->order(100) unless defined $self->order; return $self; }
sub arguments { { url => { constructor => 1 }, } }
sub take_action { my $self = shift; # Return now if the URL is not set return 1 unless ($self->argument_value('url')); # Return now if the response is already sent (i.e., too late to redirect) return 0 unless Jifty->web->response->success; # Find the URL to redirect to my $page = $self->argument_value('url'); # Set the next page and force the redirect Jifty->web->next_page($page); Jifty->web->force_redirect(1); return 1; }
1;