mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUGFIX: Fix bugs introduced by the expectation of having a DataModel.
This commit is contained in:
parent
509d32e58f
commit
b034832152
@ -133,9 +133,10 @@ class ContentController extends Controller {
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function handleRequest(SS_HTTPRequest $request) {
|
||||
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
|
||||
$child = null;
|
||||
$action = $request->param('Action');
|
||||
$this->setModel($model);
|
||||
|
||||
// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
|
||||
// control to a child controller. This allows for the creation of chains of controllers which correspond to a
|
||||
@ -144,9 +145,9 @@ class ContentController extends Controller {
|
||||
// See ModelAdController->getNestedController() for similar logic
|
||||
if(class_exists('Translatable')) Translatable::disable_locale_filter();
|
||||
// look for a page with this URLSegment
|
||||
$child = DataObject::get_one('SiteTree', sprintf (
|
||||
$child = $this->model->SiteTree->where(sprintf (
|
||||
"\"ParentID\" = %s AND \"URLSegment\" = '%s'", $this->ID, Convert::raw2sql($action)
|
||||
));
|
||||
))->First();
|
||||
if(class_exists('Translatable')) Translatable::enable_locale_filter();
|
||||
|
||||
// if we can't find a page with this URLSegment try to find one that used to have
|
||||
@ -180,7 +181,7 @@ class ContentController extends Controller {
|
||||
$request->shiftAllParams();
|
||||
$request->shift();
|
||||
|
||||
$response = ModelAsController::controller_for($child)->handleRequest($request);
|
||||
$response = ModelAsController::controller_for($child)->handleRequest($request, $model);
|
||||
} else {
|
||||
// If a specific locale is requested, and it doesn't match the page found by URLSegment,
|
||||
// look for a translation and redirect (see #5001). Only happens on the last child in
|
||||
@ -197,7 +198,7 @@ class ContentController extends Controller {
|
||||
}
|
||||
|
||||
Director::set_current_page($this->data());
|
||||
$response = parent::handleRequest($request);
|
||||
$response = parent::handleRequest($request, $model);
|
||||
Director::set_current_page(null);
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,9 @@ class ModelAsController extends Controller implements NestedController {
|
||||
* @uses ModelAsController::getNestedController()
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function handleRequest(SS_HTTPRequest $request) {
|
||||
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
|
||||
$this->request = $request;
|
||||
$this->setModel($model);
|
||||
|
||||
$this->pushCurrent();
|
||||
|
||||
@ -64,7 +65,7 @@ class ModelAsController extends Controller implements NestedController {
|
||||
$result = $this->getNestedController();
|
||||
|
||||
if($result instanceof RequestHandler) {
|
||||
$result = $result->handleRequest($this->request);
|
||||
$result = $result->handleRequest($this->request, $model);
|
||||
} else if(!($result instanceof SS_HTTPResponse)) {
|
||||
user_error("ModelAsController::getNestedController() returned bad object type '" .
|
||||
get_class($result)."'", E_USER_WARNING);
|
||||
|
@ -91,8 +91,9 @@ class RootURLController extends Controller {
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function handleRequest(SS_HTTPRequest $request) {
|
||||
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
|
||||
self::$is_at_root = true;
|
||||
$this->setModel($model);
|
||||
|
||||
$this->pushCurrent();
|
||||
$this->init();
|
||||
@ -109,7 +110,7 @@ class RootURLController extends Controller {
|
||||
$request->match('$URLSegment//$Action', true);
|
||||
|
||||
$controller = new ModelAsController();
|
||||
$result = $controller->handleRequest($request);
|
||||
$result = $controller->handleRequest($request, $model);
|
||||
|
||||
$this->popCurrent();
|
||||
return $result;
|
||||
|
@ -39,7 +39,7 @@ class ErrorPage extends Page {
|
||||
public static function response_for($statusCode) {
|
||||
// first attempt to dynamically generate the error page
|
||||
if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = $statusCode")) {
|
||||
return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''));
|
||||
return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
|
||||
}
|
||||
|
||||
// then fall back on a cached version
|
||||
|
Loading…
Reference in New Issue
Block a user