Quick links: Content - sections - sub sections
EN FR

There are two types of redirection objects available:

  • jResponseRedirect: redirects to an action of the application with optional parameters
  • jResponseRedirectUrl: redirects to any URL, in particularly external url.

jResponseRedirect

To specify a redirection to an action, you indicate 'redirect' as the type of response:


$resp = $this->getResponse('redirect');

You have then an instance of jResponseRedirect in $resp.

You have three properties on this object:

  • action to indicate the action to redirect (an action selector)
  • params to indicate parameters for this actions (optional)
  • anchor to indicate an anchor in the url #anchor (optional)

Example:


$resp->action = "mymodule~mycontroller:mymethod";
$resp->params = array('foo' => 'bar');
$resp->anchor = 'yo';

And then


return $resp;

jResponseRedirectUrl

This type of response ("redirectUrl") is used to redirect to an external url (or an url which is not pointing to your application).


$resp = $this->getResponse('redirectUrl');

The single property of this response is url, where you indicate the url to redirect.


$resp->url = "http://jelix.org";
return $resp;

Temporary or permanent redirection

By default, redirections are temporary redirection (http status code: 303). If you want to indicate a permanent redirection, you have to set the property $temporary to false.


$resp->temporary = false;