BUGFIX: Fix bugs introduced by the expectation of having a DataModel.

This commit is contained in:
Sam Minnee 2011-05-01 17:42:27 +12:00
parent 509d32e58f
commit b034832152
4 changed files with 13 additions and 10 deletions

View File

@ -133,9 +133,10 @@ class ContentController extends Controller {
* *
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function handleRequest(SS_HTTPRequest $request) { public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$child = null; $child = null;
$action = $request->param('Action'); $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 // 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 // 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 // See ModelAdController->getNestedController() for similar logic
if(class_exists('Translatable')) Translatable::disable_locale_filter(); if(class_exists('Translatable')) Translatable::disable_locale_filter();
// look for a page with this URLSegment // 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) "\"ParentID\" = %s AND \"URLSegment\" = '%s'", $this->ID, Convert::raw2sql($action)
)); ))->First();
if(class_exists('Translatable')) Translatable::enable_locale_filter(); 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 // 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->shiftAllParams();
$request->shift(); $request->shift();
$response = ModelAsController::controller_for($child)->handleRequest($request); $response = ModelAsController::controller_for($child)->handleRequest($request, $model);
} else { } else {
// If a specific locale is requested, and it doesn't match the page found by URLSegment, // 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 // 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()); Director::set_current_page($this->data());
$response = parent::handleRequest($request); $response = parent::handleRequest($request, $model);
Director::set_current_page(null); Director::set_current_page(null);
} }

View File

@ -36,8 +36,9 @@ class ModelAsController extends Controller implements NestedController {
* @uses ModelAsController::getNestedController() * @uses ModelAsController::getNestedController()
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function handleRequest(SS_HTTPRequest $request) { public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$this->request = $request; $this->request = $request;
$this->setModel($model);
$this->pushCurrent(); $this->pushCurrent();
@ -64,7 +65,7 @@ class ModelAsController extends Controller implements NestedController {
$result = $this->getNestedController(); $result = $this->getNestedController();
if($result instanceof RequestHandler) { if($result instanceof RequestHandler) {
$result = $result->handleRequest($this->request); $result = $result->handleRequest($this->request, $model);
} else if(!($result instanceof SS_HTTPResponse)) { } else if(!($result instanceof SS_HTTPResponse)) {
user_error("ModelAsController::getNestedController() returned bad object type '" . user_error("ModelAsController::getNestedController() returned bad object type '" .
get_class($result)."'", E_USER_WARNING); get_class($result)."'", E_USER_WARNING);

View File

@ -91,8 +91,9 @@ class RootURLController extends Controller {
* @param SS_HTTPRequest $request * @param SS_HTTPRequest $request
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function handleRequest(SS_HTTPRequest $request) { public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
self::$is_at_root = true; self::$is_at_root = true;
$this->setModel($model);
$this->pushCurrent(); $this->pushCurrent();
$this->init(); $this->init();
@ -109,7 +110,7 @@ class RootURLController extends Controller {
$request->match('$URLSegment//$Action', true); $request->match('$URLSegment//$Action', true);
$controller = new ModelAsController(); $controller = new ModelAsController();
$result = $controller->handleRequest($request); $result = $controller->handleRequest($request, $model);
$this->popCurrent(); $this->popCurrent();
return $result; return $result;

View File

@ -39,7 +39,7 @@ class ErrorPage extends Page {
public static function response_for($statusCode) { public static function response_for($statusCode) {
// first attempt to dynamically generate the error page // first attempt to dynamically generate the error page
if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = $statusCode")) { 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 // then fall back on a cached version