mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Added Director::redirected_to / Controller::redirectedTo() for redirection-detection
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41093 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
83020ccc03
commit
c0660c147b
@ -414,6 +414,14 @@ class Controller extends ViewableData {
|
|||||||
$this->response->redirect($url);
|
$this->response->redirect($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether a redirection has been requested.
|
||||||
|
* @return string If redirect() has been called, it will return the URL redirected to. Otherwise, it will return null;
|
||||||
|
*/
|
||||||
|
function redirectedTo() {
|
||||||
|
return $this->response->getHeader('Location');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Session object representing this Controller's session
|
* Get the Session object representing this Controller's session
|
||||||
* @return Session
|
* @return Session
|
||||||
|
@ -188,14 +188,22 @@ class Director {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to another page.
|
* Redirect to another page.
|
||||||
* - $url can be an absolute URL
|
* - $url can be an absolute URL
|
||||||
* - or it can be a URL relative to the "site base"
|
* - or it can be a URL relative to the "site base"
|
||||||
* - if it is just a word without an slashes, then it redirects to another action on the current controller.
|
* - if it is just a word without an slashes, then it redirects to another action on the current controller.
|
||||||
*/
|
*/
|
||||||
static function redirect($url) {
|
static function redirect($url) {
|
||||||
Controller::curr()->redirect($url);
|
Controller::curr()->redirect($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether a redirection has been requested.
|
||||||
|
* @return string If redirect() has been called, it will return the URL redirected to. Otherwise, it will return null;
|
||||||
|
*/
|
||||||
|
static function redirected_to() {
|
||||||
|
Controller::curr()->redirectedTo();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses either the HTTP_REFERER or a manually set request-variable called _REDIRECT_BACK_URL.
|
* Uses either the HTTP_REFERER or a manually set request-variable called _REDIRECT_BACK_URL.
|
||||||
* This variable is needed in scenarios where not HTTP-Referer is sent (e.g when calling a page
|
* This variable is needed in scenarios where not HTTP-Referer is sent (e.g when calling a page
|
||||||
|
@ -73,7 +73,11 @@ class HTTPResponse extends Object {
|
|||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
function getHeader($header) {
|
function getHeader($header) {
|
||||||
return $this->headers[$header];
|
if(isset($this->headers[$header])) {
|
||||||
|
return $this->headers[$header];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect($dest) {
|
function redirect($dest) {
|
||||||
|
Loading…
Reference in New Issue
Block a user