From b056c5abbfb3cf973d09ebcbdd43ea9fe4131b1b Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 27 Nov 2006 05:23:33 +0000 Subject: [PATCH] refactoring scaffold, if var $uses exists scaffold will use the first model specified in the array, if $scaffold is an array, only methods added to the array will allow scaffold to render, ex: var $scaffold = array('index'); only the index action will be rendered git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3988 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/scaffold.php | 37 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 91a5d9a7a..492eef85a 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -99,10 +99,26 @@ class Scaffold extends Object { $this->controller = &$controller; $this->name = $controller->name; $this->action = $controller->action; - $this->modelClass = Inflector::classify($this->name); - $this->modelKey = Inflector::underscore($this->modelClass); + if (!in_array('Form', $this->controller->helpers)) { + $this->controller->helpers[] = 'Form'; + } + $this->controller->constructClasses(); + if(!empty($controller->uses) && class_exists($controller->uses[0])) { + $controller->modelClass = $controller->uses[0]; + $controller->modelKey = Inflector::underscore($controller->modelClass); + } + + $this->modelClass = $controller->modelClass; + $this->modelKey = $controller->modelKey; + + if(!is_object($this->controller->{$this->modelClass})) { + return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base))); + } + $this->ScaffoldModel = &$this->controller->{$this->modelClass}; + $this->viewPath = Inflector::underscore($this->name); $this->scaffoldTitle = Inflector::humanize($this->viewPath); + $this->scaffoldActions = $controller->scaffold; $this->controller->pageTitle= 'Scaffold :: ' . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle; $path = '/'; /*if(is_null($controller->plugin)) { @@ -119,11 +135,6 @@ class Scaffold extends Object { $this->controller->set('humanSingularName', Inflector::humanize($this->modelKey)); $this->controller->set('humanPluralName', Inflector::humanize($this->viewPath)); - if (!in_array('Form', $this->controller->helpers)) { - $this->controller->helpers[] = 'Form'; - } - $this->controller->constructClasses(); - $this->ScaffoldModel = &$this->controller->{$this->modelClass}; $alias = null; if(!empty($this->ScaffoldModel->alias)) { $alias = array_combine(array_keys($this->ScaffoldModel->alias), array_keys($this->ScaffoldModel->alias)); @@ -285,10 +296,10 @@ class Scaffold extends Object { $this->controller->set('fieldNames', $this->controller->generateFieldNames($this->__rebuild($this->controller->data))); $this->controller->validateErrors($this->ScaffoldModel); - if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $thtml . '.thtml')) { + if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $action . '.thtml')) { return $this->controller->render($viewFileName, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $thtml . '.thtml'); - } elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml')) { - return $this->controller->render($viewFileName, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml'); + } elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) { + return $this->controller->render($viewFileName, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml'); } else { return $this->controller->render($viewFileName, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'edit.thtml'); } @@ -402,8 +413,10 @@ class Scaffold extends Object { $db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); if (isset($db)) { - $scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'); - if (in_array($params['action'], $scaffoldActions)) { + if(empty($this->scaffoldActions)) { + $this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'); + } + if (in_array($params['action'], $this->scaffoldActions)) { switch($params['action']) { case 'index':