diff --git a/code/controller/ContentController.php b/code/controller/ContentController.php index 940e41cc..22da4a4d 100755 --- a/code/controller/ContentController.php +++ b/code/controller/ContentController.php @@ -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); } diff --git a/code/controller/ModelAsController.php b/code/controller/ModelAsController.php index 1faac691..8789f2da 100755 --- a/code/controller/ModelAsController.php +++ b/code/controller/ModelAsController.php @@ -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); diff --git a/code/controller/RootURLController.php b/code/controller/RootURLController.php index c9ebfacf..5d01e32d 100755 --- a/code/controller/RootURLController.php +++ b/code/controller/RootURLController.php @@ -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; diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index 753097c5..130157f8 100755 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -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