mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
#1432, #1557 - Added Director::set_status_code() and Director::get_status_code(), and used this to fix 404 errors. (merged from branches/2.2.0@45907, r45443)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@46099 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
4e5bdfc3fe
commit
e19ec7d93f
@ -45,6 +45,14 @@ class Controller extends ViewableData {
|
||||
return $this->urlParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTPResponse object that this controller is building up.
|
||||
* Can be used to set the status code and headers
|
||||
*/
|
||||
function getResponse() {
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the appropriate action handler. If none is given, use defaultAction to display
|
||||
* a template. The default action will be appropriate in most cases where displaying data
|
||||
|
@ -243,6 +243,20 @@ class Director {
|
||||
return Controller::curr()->redirectedTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP status code
|
||||
*/
|
||||
static function set_status_code($code) {
|
||||
return Controller::curr()->getResponse()->setStatusCode($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current HTTP status code
|
||||
*/
|
||||
static function get_status_code() {
|
||||
return Controller::curr()->getResponse()->getStatusCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* Redirect back
|
||||
*
|
||||
|
@ -53,6 +53,9 @@ class HTTPResponse extends Object {
|
||||
if(isset(self::$status_codes[$code])) $this->statusCode = $code;
|
||||
else user_error("Unrecognised HTTP status code '$code'", E_USER_WARNING);
|
||||
}
|
||||
function getStatusCode() {
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
function setBody($body) {
|
||||
$this->body = $body;
|
||||
|
@ -31,8 +31,7 @@ class ModelAsController extends Controller implements NestedController {
|
||||
$child = DataObject::get_one("SiteTree", "URLSegment = '$SQL_URLSegment'");
|
||||
}
|
||||
if(!$child) {
|
||||
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
Director::set_status_code(404);
|
||||
$child = $this->get404Page();
|
||||
}
|
||||
|
||||
|
@ -106,11 +106,6 @@ class ErrorPage extends Page {
|
||||
* Controller for ErrorPages.
|
||||
*/
|
||||
class ErrorPage_Controller extends Page_Controller {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
$this->response->setStatusCode($this->dataRecord->ErrorCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user