Chapter: Doing a redirection
|« Define a customized response||^ Main concepts||Web services »|
There are two types of redirection objects available:
jResponseRedirect: redirects to an action of the application with optional parameters
jResponseRedirectUrl: redirects to any URL
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:
actionto indicate the action to redirect (an action selector)
paramsto indicate parameters for this actions (optional)
anchorto indicate an anchor in the url #anchor (optional)
$resp->action = "mymodule~mycontroller:mycontroller"; $resp->params = array('foo' => 'bar'); $resp->anchor = 'yo';
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;