mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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
This commit is contained in:
parent
bce8e016d2
commit
b056c5abbf
1 changed files with 25 additions and 12 deletions
|
@ -99,10 +99,26 @@ class Scaffold extends Object {
|
||||||
$this->controller = &$controller;
|
$this->controller = &$controller;
|
||||||
$this->name = $controller->name;
|
$this->name = $controller->name;
|
||||||
$this->action = $controller->action;
|
$this->action = $controller->action;
|
||||||
$this->modelClass = Inflector::classify($this->name);
|
if (!in_array('Form', $this->controller->helpers)) {
|
||||||
$this->modelKey = Inflector::underscore($this->modelClass);
|
$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->viewPath = Inflector::underscore($this->name);
|
||||||
$this->scaffoldTitle = Inflector::humanize($this->viewPath);
|
$this->scaffoldTitle = Inflector::humanize($this->viewPath);
|
||||||
|
$this->scaffoldActions = $controller->scaffold;
|
||||||
$this->controller->pageTitle= 'Scaffold :: ' . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
|
$this->controller->pageTitle= 'Scaffold :: ' . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
|
||||||
$path = '/';
|
$path = '/';
|
||||||
/*if(is_null($controller->plugin)) {
|
/*if(is_null($controller->plugin)) {
|
||||||
|
@ -119,11 +135,6 @@ class Scaffold extends Object {
|
||||||
$this->controller->set('humanSingularName', Inflector::humanize($this->modelKey));
|
$this->controller->set('humanSingularName', Inflector::humanize($this->modelKey));
|
||||||
$this->controller->set('humanPluralName', Inflector::humanize($this->viewPath));
|
$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;
|
$alias = null;
|
||||||
if(!empty($this->ScaffoldModel->alias)) {
|
if(!empty($this->ScaffoldModel->alias)) {
|
||||||
$alias = array_combine(array_keys($this->ScaffoldModel->alias), array_keys($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->set('fieldNames', $this->controller->generateFieldNames($this->__rebuild($this->controller->data)));
|
||||||
$this->controller->validateErrors($this->ScaffoldModel);
|
$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');
|
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')) {
|
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) {
|
||||||
return $this->controller->render($viewFileName, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml');
|
return $this->controller->render($viewFileName, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml');
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->render($viewFileName, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'edit.thtml');
|
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);
|
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
|
||||||
|
|
||||||
if (isset($db)) {
|
if (isset($db)) {
|
||||||
$scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
|
if(empty($this->scaffoldActions)) {
|
||||||
if (in_array($params['action'], $scaffoldActions)) {
|
$this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
|
||||||
|
}
|
||||||
|
if (in_array($params['action'], $this->scaffoldActions)) {
|
||||||
switch($params['action'])
|
switch($params['action'])
|
||||||
{
|
{
|
||||||
case 'index':
|
case 'index':
|
||||||
|
|
Loading…
Add table
Reference in a new issue