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
This commit is contained in:
Sam Minnee 2010-02-04 05:16:44 +00:00
parent ba02e1dc9f
commit 5efb72ce26

View File

@ -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();