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:
Sam Minnee 2007-08-31 00:26:41 +00:00
parent 83020ccc03
commit c0660c147b
3 changed files with 24 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {