From 5efb72ce2611cf75584d1ae0d7f97a160c95a87b Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 4 Feb 2010 05:16:44 +0000 Subject: [PATCH] BUGFIX: Let ModelAsController::init() extensions trigger redirections. (from r97767) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98221 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/ModelAsController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/control/ModelAsController.php b/core/control/ModelAsController.php index 414a33595..d037e8dcf 100755 --- a/core/control/ModelAsController.php +++ b/core/control/ModelAsController.php @@ -19,7 +19,7 @@ class ModelAsController extends Controller implements NestedController { public static function controller_for(SiteTree $sitetree, $action = null) { if($sitetree->class == 'SiteTree') $controller = "ContentController"; else $controller = "{$sitetree->class}_Controller"; - + if($action && class_exists($controller . '_' . ucfirst($action))) { $controller = $controller . '_' . ucfirst($action); } @@ -29,6 +29,7 @@ class ModelAsController extends Controller implements NestedController { public function init() { singleton('SiteTree')->extend('modelascontrollerInit', $this); + parent::init(); } /** @@ -39,11 +40,14 @@ class ModelAsController extends Controller implements NestedController { $this->request = $request; $this->pushCurrent(); + + // Create a response just in case init() decides to redirect + $this->response = new SS_HTTPResponse(); + $this->init(); // If the database has not yet been created, redirect to the build page. if(!DB::isActive() || !ClassInfo::hasTable('SiteTree')) { - $this->response = new SS_HTTPResponse(); $this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)); $this->popCurrent();