mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing Scaffold in 1.2.x.x when setting Controller::persistModel = true;
Corrected error message with correct method name in scaffold_error templates. Removed unneeded check for Controller::persistModel in 1.2.x.x. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4038 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
83afee9a52
commit
7b6e81c1e2
3 changed files with 158 additions and 207 deletions
|
@ -308,9 +308,6 @@ class Controller extends Object {
|
||||||
$cached = false;
|
$cached = false;
|
||||||
$object = null;
|
$object = null;
|
||||||
|
|
||||||
if ($this->persistModel === true){
|
|
||||||
uses('neat_array');
|
|
||||||
}
|
|
||||||
if($this->uses === false) {
|
if($this->uses === false) {
|
||||||
if(!class_exists($this->modelClass)){
|
if(!class_exists($this->modelClass)){
|
||||||
loadModel($this->modelClass);
|
loadModel($this->modelClass);
|
||||||
|
@ -1090,7 +1087,7 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
/* SVN FILE: $Id$ */
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scaffold.
|
* Scaffold.
|
||||||
*
|
*
|
||||||
|
@ -27,7 +26,6 @@
|
||||||
* @lastmodified $Date$
|
* @lastmodified $Date$
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scaffolding is a set of automatic views, forms and controllers for starting web development work faster.
|
* Scaffolding is a set of automatic views, forms and controllers for starting web development work faster.
|
||||||
*
|
*
|
||||||
|
@ -40,14 +38,12 @@
|
||||||
* @subpackage cake.cake.libs.controller
|
* @subpackage cake.cake.libs.controller
|
||||||
*/
|
*/
|
||||||
class Scaffold extends Object {
|
class Scaffold extends Object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller object
|
* Controller object
|
||||||
*
|
*
|
||||||
* @var Controller
|
* @var Controller
|
||||||
*/
|
*/
|
||||||
var $controller = null;
|
var $controller = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of controller to scaffold
|
* Name of controller to scaffold
|
||||||
*
|
*
|
||||||
|
@ -59,49 +55,46 @@ class Scaffold extends Object {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $action = null;
|
var $action = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class name of model
|
* Class name of model
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $modelClass = null;
|
var $modelClass = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry key of model
|
* Registry key of model
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $modelKey = null;
|
var $modelKey = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View path for scaffolded controller
|
* View path for scaffolded controller
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $viewPath = null;
|
var $viewPath = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title HTML element for current scaffolded view
|
* Title HTML element for current scaffolded view
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $scaffoldTitle = null;
|
var $scaffoldTitle = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct and set up given controller with given parameters.
|
* Construct and set up given controller with given parameters.
|
||||||
*
|
*
|
||||||
* @param string $controller_class Name of controller
|
* @param string $controller_class Name of controller
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*/
|
*/
|
||||||
function __construct(&$controller, $params) {
|
function __construct(&$controller, $params) {
|
||||||
$this->controller = &$controller;
|
$this->controller = &$controller;
|
||||||
$this->name = $controller->name;
|
$this->name = $controller->name;
|
||||||
$this->action = $controller->action;
|
$this->action = $controller->action;
|
||||||
|
|
||||||
if (!in_array('Form', $this->controller->helpers)) {
|
if (!in_array('Form', $this->controller->helpers)) {
|
||||||
$this->controller->helpers[] = 'Form';
|
$this->controller->helpers[] = 'Form';
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->controller->constructClasses() === false) {
|
if($this->controller->constructClasses() === false) {
|
||||||
return $this->cakeError('missingModel', array(array('className' => $this->modelKey, 'webroot' => '', 'base' => $this->controller->base)));
|
return $this->cakeError('missingModel', array(array('className' => $this->modelKey, 'webroot' => '', 'base' => $this->controller->base)));
|
||||||
}
|
}
|
||||||
|
@ -110,7 +103,6 @@ class Scaffold extends Object {
|
||||||
$controller->modelClass = $controller->uses[0];
|
$controller->modelClass = $controller->uses[0];
|
||||||
$controller->modelKey = Inflector::underscore($controller->modelClass);
|
$controller->modelKey = Inflector::underscore($controller->modelClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->modelClass = $controller->modelClass;
|
$this->modelClass = $controller->modelClass;
|
||||||
$this->modelKey = $controller->modelKey;
|
$this->modelKey = $controller->modelKey;
|
||||||
|
|
||||||
|
@ -118,17 +110,11 @@ class Scaffold extends Object {
|
||||||
return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base)));
|
return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base)));
|
||||||
}
|
}
|
||||||
$this->ScaffoldModel =& $this->controller->{$this->modelClass};
|
$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->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)) {
|
|
||||||
$path = '/';
|
|
||||||
} else {
|
|
||||||
$path = '/'.$controller->plugin.'/';
|
|
||||||
}*/
|
|
||||||
$this->controller->set('path', $path);
|
$this->controller->set('path', $path);
|
||||||
$this->controller->set('controllerName', $this->name);
|
$this->controller->set('controllerName', $this->name);
|
||||||
$this->controller->set('controllerAction', $this->action);
|
$this->controller->set('controllerAction', $this->action);
|
||||||
|
@ -137,19 +123,16 @@ class Scaffold extends Object {
|
||||||
$this->controller->set('viewPath', $this->viewPath);
|
$this->controller->set('viewPath', $this->viewPath);
|
||||||
$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));
|
||||||
|
|
||||||
$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));
|
||||||
}
|
}
|
||||||
$this->controller->set('alias', $alias);
|
$this->controller->set('alias', $alias);
|
||||||
|
|
||||||
$this->controller->set('primaryKey', $this->ScaffoldModel->primaryKey);
|
$this->controller->set('primaryKey', $this->ScaffoldModel->primaryKey);
|
||||||
$this->controller->set('displayField', $this->ScaffoldModel->getDisplayfield());
|
$this->controller->set('displayField', $this->ScaffoldModel->getDisplayfield());
|
||||||
|
|
||||||
$this->__scaffold($params);
|
$this->__scaffold($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a view view of scaffolded Model.
|
* Renders a view view of scaffolded Model.
|
||||||
*
|
*
|
||||||
|
@ -157,40 +140,37 @@ class Scaffold extends Object {
|
||||||
* @return A rendered view of a row from Models database table
|
* @return A rendered view of a row from Models database table
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __scaffoldView($params) {
|
function __scaffoldView($params) {
|
||||||
if ($this->controller->_beforeScaffold('view')) {
|
if ($this->controller->_beforeScaffold('view')) {
|
||||||
$this->controller->data = $this->ScaffoldModel->read();
|
|
||||||
|
|
||||||
if(isset($params['pass'][0])){
|
if(isset($params['pass'][0])){
|
||||||
$this->controller->{$this->modelKey}->id = $params['pass'][0];
|
$this->ScaffoldModel->id = $params['pass'][0];
|
||||||
|
|
||||||
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||||
$this->controller->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::view().');
|
$this->controller->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::view().');
|
||||||
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::view().',
|
return $this->controller->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::view().',
|
||||||
'/' . Inflector::underscore($this->controller->viewPath));
|
'/' . Inflector::underscore($this->controller->viewPath));
|
||||||
}
|
}
|
||||||
$this->controller->set('data', $this->controller->data);
|
$this->controller->data = $this->ScaffoldModel->read();
|
||||||
$this->controller->set('fieldNames',
|
$this->controller->set('data', $this->controller->data);
|
||||||
$this->controller->generateFieldNames($this->controller->data, false));
|
$this->controller->set('fieldNames', $this->controller->generateFieldNames($this->controller->data, false));
|
||||||
|
|
||||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml')) {
|
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml')) {
|
||||||
return $this->controller->render($this->action, '', APP . 'views' . DS . $this->viewPath
|
return $this->controller->render($this->action, '',
|
||||||
. DS . 'scaffold.view.thtml');
|
APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml');
|
||||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml')) {
|
} elseif (file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml')) {
|
||||||
return $this->controller->render($this->action, '', APP . 'views' . DS . 'scaffold'
|
return $this->controller->render($this->action, '',
|
||||||
. DS . 'scaffold.view.thtml');
|
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml');
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->render($this->action, '', LIBS . 'view' . DS . 'templates'
|
return $this->controller->render($this->action, '',
|
||||||
. DS . 'scaffolds' . DS . 'view.thtml');
|
LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'view.thtml');
|
||||||
}
|
}
|
||||||
} else if($this->controller->_scaffoldError('view') === false) {
|
|
||||||
return $this->__scaffoldError();
|
} elseif ($this->controller->_scaffoldError('view') === false) {
|
||||||
|
return $this->__scaffoldError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders List view of scaffolded Model.
|
* Renders List view of scaffolded Model.
|
||||||
*
|
*
|
||||||
|
@ -198,27 +178,27 @@ class Scaffold extends Object {
|
||||||
* @return A rendered view listing rows from Models database table
|
* @return A rendered view listing rows from Models database table
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __scaffoldIndex($params) {
|
function __scaffoldIndex($params) {
|
||||||
|
if ($this->controller->_beforeScaffold('index')) {
|
||||||
|
|
||||||
if ($this->controller->_beforeScaffold('index')) {
|
$this->controller->set('fieldNames', $this->controller->generateFieldNames(null, false));
|
||||||
|
$this->ScaffoldModel->recursive = 0;
|
||||||
|
$this->controller->set('data', $this->ScaffoldModel->findAll(null, null, $this->modelClass.'.'.$this->ScaffoldModel->primaryKey.' DESC'));
|
||||||
|
|
||||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames(null, false));
|
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml')) {
|
||||||
$this->ScaffoldModel->recursive = 0;
|
return $this->controller->render($this->action, '',
|
||||||
$this->controller->set('data', $this->ScaffoldModel->findAll(null, null, $this->modelClass.'.'.$this->ScaffoldModel->primaryKey.' DESC'));
|
APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml');
|
||||||
|
} elseif (file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml')) {
|
||||||
|
return $this->controller->render($this->action, '',
|
||||||
|
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml');
|
||||||
|
} else {
|
||||||
|
return $this->controller->render($this->action, '',
|
||||||
|
LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'index.thtml');
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml')) {
|
} elseif ($this->controller->_scaffoldError('index') === false) {
|
||||||
return $this->controller->render($this->action, '',
|
return $this->__scaffoldError();
|
||||||
APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml');
|
}
|
||||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml')) {
|
|
||||||
return $this->controller->render($this->action, '',
|
|
||||||
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml');
|
|
||||||
} else {
|
|
||||||
return $this->controller->render($this->action, '', LIBS . 'view' . DS . 'templates'
|
|
||||||
. DS . 'scaffolds' . DS . 'index.thtml');
|
|
||||||
}
|
|
||||||
} else if($this->controller->_scaffoldError('index') === false) {
|
|
||||||
return $this->__scaffoldError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,31 +209,29 @@ class Scaffold extends Object {
|
||||||
* @return A rendered view with a form to edit or add a record in the Models database table
|
* @return A rendered view with a form to edit or add a record in the Models database table
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __scaffoldForm($params = array(), $action = 'edit') {
|
function __scaffoldForm($params = array(), $action = 'edit') {
|
||||||
if ($this->controller->_beforeScaffold($action)) {
|
if ($this->controller->_beforeScaffold($action)) {
|
||||||
|
|
||||||
$this->controller->set('formName', ucwords($action));
|
$this->controller->set('formName', ucwords($action));
|
||||||
|
|
||||||
if ($action == 'edit') {
|
if ($action == 'edit') {
|
||||||
|
|
||||||
if(isset($params['pass'][0])){
|
if(isset($params['pass'][0])){
|
||||||
$this->controller->{$this->modelKey}->id = $params['pass'][0];
|
$this->ScaffoldModel->id = $params['pass'][0];
|
||||||
|
|
||||||
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||||
$this->controller->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::edit().');
|
$this->controller->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::edit().');
|
||||||
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::edit().',
|
return $this->controller->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::edit().',
|
||||||
'/' . Inflector::underscore($this->controller->viewPath));
|
'/' . Inflector::underscore($this->controller->viewPath));
|
||||||
}
|
}
|
||||||
$this->controller->data = $this->ScaffoldModel->read();
|
$this->controller->data = $this->ScaffoldModel->read();
|
||||||
$this->controller->set('fieldNames',
|
$this->controller->set('fieldNames', $this->controller->generateFieldNames($this->controller->data));
|
||||||
$this->controller->generateFieldNames($this->controller->data));
|
$this->controller->set('data', $this->controller->data);
|
||||||
$this->controller->set('data', $this->controller->data);
|
|
||||||
} else {
|
} else {
|
||||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $action . '.thtml')) {
|
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $action . '.thtml')) {
|
||||||
return $this->controller->render($action, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $action . '.thtml');
|
return $this->controller->render($action, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $action . '.thtml');
|
||||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) {
|
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) {
|
||||||
|
@ -261,13 +239,12 @@ class Scaffold extends Object {
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->render($action, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.thtml');
|
return $this->controller->render($action, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.thtml');
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if($this->controller->_scaffoldError($action) === false) {
|
} else if($this->controller->_scaffoldError($action) === false) {
|
||||||
return $this->__scaffoldError();
|
return $this->__scaffoldError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Saves or updates a model.
|
* Saves or updates a model.
|
||||||
*
|
*
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
@ -335,7 +312,6 @@ class Scaffold extends Object {
|
||||||
return $this->__scaffoldError();
|
return $this->__scaffoldError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a delete on given scaffolded Model.
|
* Performs a delete on given scaffolded Model.
|
||||||
*
|
*
|
||||||
|
@ -343,56 +319,56 @@ class Scaffold extends Object {
|
||||||
* @return success on delete error if delete fails
|
* @return success on delete error if delete fails
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __scaffoldDelete($params = array()) {
|
function __scaffoldDelete($params = array()) {
|
||||||
if ($this->controller->_beforeScaffold('delete')) {
|
if ($this->controller->_beforeScaffold('delete')) {
|
||||||
|
|
||||||
|
if(isset($params['pass'][0])){
|
||||||
$id = $params['pass'][0];
|
$id = $params['pass'][0];
|
||||||
|
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||||
|
$this->controller->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::delete().');
|
||||||
|
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
||||||
|
} else {
|
||||||
|
return $this->controller->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::delete().',
|
||||||
|
'/' . Inflector::underscore($this->controller->viewPath));
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->ScaffoldModel->del($id)) {
|
if ($this->ScaffoldModel->del($id)) {
|
||||||
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||||
$this->controller->Session->setFlash(
|
$this->controller->Session->setFlash('The ' . Inflector::humanize($this->modelClass) . ' with id: ' . $id . ' has been deleted.');
|
||||||
'The ' . Inflector::humanize($this->modelClass) . ' with id: ' . $id
|
$this->controller->redirect('/' . $this->viewPath);
|
||||||
. ' has been deleted.');
|
|
||||||
$this->controller->redirect('/' . $this->viewPath);
|
|
||||||
} else {
|
|
||||||
return $this->controller->flash(
|
|
||||||
'The ' . Inflector::humanize($this->modelClass) . ' with id: ' . $id
|
|
||||||
. ' has been deleted.', '/' . $this->viewPath);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
return $this->controller->flash('The ' . Inflector::humanize($this->modelClass) . ' with id: ' . $id . ' has been deleted.', '/' . $this->viewPath);
|
||||||
$this->controller->Session->setFlash(
|
|
||||||
'There was an error deleting the ' . Inflector::humanize($this->modelClass)
|
|
||||||
. ' with the id ' . $id);
|
|
||||||
$this->controller->redirect('/' . $this->viewPath);
|
|
||||||
} else {
|
|
||||||
return $this->controller->flash(
|
|
||||||
'There was an error deleting the ' . Inflector::humanize($this->modelClass)
|
|
||||||
. ' with the id ' . $id, '/' . $this->viewPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if($this->controller->_scaffoldError('delete') === false) {
|
} else {
|
||||||
return $this->__scaffoldError();
|
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||||
}
|
$this->controller->Session->setFlash('There was an error deleting the ' . Inflector::humanize($this->modelClass) . ' with the id ' . $id);
|
||||||
}
|
$this->controller->redirect('/' . $this->viewPath);
|
||||||
|
} else {
|
||||||
|
return $this->controller->flash('There was an error deleting the ' . Inflector::humanize($this->modelClass) . ' with the id ' . $id, '/' . $this->viewPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($this->controller->_scaffoldError('delete') === false) {
|
||||||
|
return $this->__scaffoldError();
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return error
|
||||||
*/
|
*/
|
||||||
function __scaffoldError() {
|
function __scaffoldError() {
|
||||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS. 'scaffold.error.thtml')) {
|
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS. 'scaffold.error.thtml')) {
|
||||||
return $this->controller->render($this->action, '', APP . 'views' . DS . $this->viewPath
|
return $this->controller->render($this->action, '',
|
||||||
. DS . 'scaffolds' . DS . 'scaffold.error.thtml');
|
APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.error.thtml');
|
||||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.error.thtml')) {
|
} elseif (file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.error.thtml')) {
|
||||||
return $this->controller->render($this->action, '', APP . 'views' . DS . 'scaffold'
|
return $this->controller->render($this->action, '',
|
||||||
. DS . 'scaffold.error.thtml');
|
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.error.thtml');
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->render($this->action, '', LIBS . 'view' . DS . 'templates' . DS
|
return $this->controller->render($this->action, '',
|
||||||
. 'errors' . DS . 'scaffold_error.thtml');
|
LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . 'scaffold_error.thtml');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When forms are submited the arrays need to be rebuilt if
|
* When forms are submited the arrays need to be rebuilt if
|
||||||
* an error occured, here the arrays are rebuilt to structure needed
|
* an error occured, here the arrays are rebuilt to structure needed
|
||||||
|
@ -400,27 +376,24 @@ class Scaffold extends Object {
|
||||||
* @param array $params data passed to forms
|
* @param array $params data passed to forms
|
||||||
* @return array rebuilds the association arrays to pass back to Controller::generateFieldNames()
|
* @return array rebuilds the association arrays to pass back to Controller::generateFieldNames()
|
||||||
*/
|
*/
|
||||||
function __rebuild($params) {
|
function __rebuild($params) {
|
||||||
foreach($params as $model => $field) {
|
foreach($params as $model => $field) {
|
||||||
if (!empty($field) && is_array($field)) {
|
if (!empty($field) && is_array($field)) {
|
||||||
$match=array_keys($field);
|
$match=array_keys($field);
|
||||||
|
|
||||||
if ($model == $match[0]) {
|
if ($model == $match[0]) {
|
||||||
$count=0;
|
$count = 0;
|
||||||
|
|
||||||
foreach($field[$model] as $value) {
|
foreach($field[$model] as $value) {
|
||||||
$params[$model][$count][$this->ScaffoldModel->primaryKey] = $value;
|
$params[$model][$count][$this->ScaffoldModel->primaryKey] = $value;
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
unset ($params[$model][$model]);
|
||||||
unset ($params[$model][$model]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When methods are now present in a controller
|
* When methods are now present in a controller
|
||||||
* scaffoldView is used to call default Scaffold methods if:
|
* scaffoldView is used to call default Scaffold methods if:
|
||||||
|
@ -435,69 +408,50 @@ class Scaffold extends Object {
|
||||||
* @since Cake v 0.10.0.172
|
* @since Cake v 0.10.0.172
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __scaffold($params) {
|
function __scaffold($params) {
|
||||||
|
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
|
||||||
|
|
||||||
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
|
if (isset($db)) {
|
||||||
|
if(empty($this->scaffoldActions)) {
|
||||||
|
$this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($db)) {
|
if (in_array($params['action'], $this->scaffoldActions)) {
|
||||||
if(empty($this->scaffoldActions)) {
|
switch($params['action']) {
|
||||||
$this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
|
case 'index':
|
||||||
|
$this->__scaffoldIndex($params);
|
||||||
|
break;
|
||||||
|
case 'view':
|
||||||
|
$this->__scaffoldView($params);
|
||||||
|
break;
|
||||||
|
case 'list':
|
||||||
|
$this->__scaffoldIndex($params);
|
||||||
|
break;
|
||||||
|
case 'add':
|
||||||
|
$this->__scaffoldForm($params, 'add');
|
||||||
|
break;
|
||||||
|
case 'edit':
|
||||||
|
$this->__scaffoldForm($params, 'edit');
|
||||||
|
break;
|
||||||
|
case 'create':
|
||||||
|
$this->__scaffoldSave($params, 'create');
|
||||||
|
break;
|
||||||
|
case 'update':
|
||||||
|
$this->__scaffoldSave($params, 'update');
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
$this->__scaffoldDelete($params);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (in_array($params['action'], $this->scaffoldActions)) {
|
} else {
|
||||||
switch($params['action'])
|
return $this->cakeError('missingAction', array(array('className' => $this->controller->name . "Controller",
|
||||||
{
|
'base' => $this->controller->base,
|
||||||
case 'index':
|
'action' => $this->action,
|
||||||
$this->__scaffoldIndex($params);
|
'webroot' => $this->controller->webroot)));
|
||||||
|
}
|
||||||
break;
|
} else {
|
||||||
|
return $this->cakeError('missingDatabase', array(array('webroot' => $this->controller->webroot)));
|
||||||
case 'view':
|
}
|
||||||
$this->__scaffoldView($params);
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'list':
|
|
||||||
$this->__scaffoldIndex($params);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'add':
|
|
||||||
$this->__scaffoldForm($params, 'add');
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'edit':
|
|
||||||
$this->__scaffoldForm($params, 'edit');
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'create':
|
|
||||||
$this->__scaffoldSave($params, 'create');
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'update':
|
|
||||||
$this->__scaffoldSave($params, 'update');
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'delete':
|
|
||||||
$this->__scaffoldDelete($params);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->cakeError('missingAction', array(
|
|
||||||
array('className' => $this->controller->name . "Controller",
|
|
||||||
'base' => $this->controller->base,
|
|
||||||
'action' => $this->action,
|
|
||||||
'webroot' => $this->controller->webroot)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->cakeError('missingDatabase', array(array('webroot' => $this->controller->webroot)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -28,6 +28,6 @@
|
||||||
<p class="error">Your must implement the following method in your controller</p>
|
<p class="error">Your must implement the following method in your controller</p>
|
||||||
<p><span class="notice"><strong>Notice:</strong> If you want to customize this error message, create <?php echo APP_DIR.DS."views/errors/scaffold_error.thtml"; ?>.</span></p>
|
<p><span class="notice"><strong>Notice:</strong> If you want to customize this error message, create <?php echo APP_DIR.DS."views/errors/scaffold_error.thtml"; ?>.</span></p>
|
||||||
<p>
|
<p>
|
||||||
function scaffoldError() {<br />
|
function _scaffoldError() {<br />
|
||||||
}<br />
|
}<br />
|
||||||
</p>
|
</p>
|
Loading…
Reference in a new issue