mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Changed scaffold class to work with new FormHelper.
Removed scaffold add.thtml. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4200 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
43f2afa6eb
commit
042d7e5f3d
2 changed files with 32 additions and 85 deletions
|
@ -210,41 +210,15 @@ class Scaffold extends Object {
|
|||
* @return A rendered view with a form to edit or add a record in the Models database table
|
||||
* @access private
|
||||
*/
|
||||
function __scaffoldForm($params = array(), $action = 'edit') {
|
||||
if ($this->controller->_beforeScaffold($action)) {
|
||||
|
||||
$this->controller->set('formName', ucwords($action));
|
||||
|
||||
if ($action == 'edit') {
|
||||
|
||||
if(isset($params['pass'][0])){
|
||||
$this->ScaffoldModel->id = $params['pass'][0];
|
||||
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||
$this->controller->Session->setFlash(sprintf(__("No id set for %s::edit()", true), Inflector::humanize($this->modelKey)));
|
||||
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__("No id set for %s::edit()", true), Inflector::humanize($this->modelKey)),
|
||||
'/' . Inflector::underscore($this->controller->viewPath));
|
||||
}
|
||||
$this->controller->data = $this->ScaffoldModel->read();
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames($this->controller->data));
|
||||
$this->controller->set('data', $this->controller->data);
|
||||
} else {
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
||||
}
|
||||
|
||||
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');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) {
|
||||
return $this->controller->render($action, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml');
|
||||
} else {
|
||||
return $this->controller->render($action, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.thtml');
|
||||
}
|
||||
|
||||
} else if($this->controller->_scaffoldError($action) === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
function __scaffoldForm($action = 'edit') {
|
||||
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');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) {
|
||||
return $this->controller->render($action, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml');
|
||||
} else {
|
||||
return $this->controller->render($action, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'edit.thtml');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Saves or updates a model.
|
||||
*
|
||||
|
@ -253,13 +227,13 @@ class Scaffold extends Object {
|
|||
* @return success on save/update, add/edit form if data is empty or error if save or update fails
|
||||
* @access private
|
||||
*/
|
||||
function __scaffoldSave($params = array(), $action = 'update') {
|
||||
function __scaffoldSave($params = array(), $action = 'edit') {
|
||||
$formName = 'Edit';
|
||||
$formAction = 'edit';
|
||||
$viewFileName = 'edit';
|
||||
$success = __('updated', true);
|
||||
|
||||
if ($action === 'create') {
|
||||
if ($action === 'add') {
|
||||
$formName = 'New';
|
||||
$formAction = 'add';
|
||||
$viewFileName = 'add';
|
||||
|
@ -271,7 +245,23 @@ class Scaffold extends Object {
|
|||
if ($this->controller->_beforeScaffold($action)) {
|
||||
|
||||
if (empty($this->controller->data)) {
|
||||
return $this->__scaffoldForm($params, $formAction);
|
||||
if ($action == 'edit') {
|
||||
if(isset($params['pass'][0])){
|
||||
$this->ScaffoldModel->id = $params['pass'][0];
|
||||
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||
$this->controller->Session->setFlash(sprintf(__("No id set for %s::edit()", true), Inflector::humanize($this->modelKey)));
|
||||
$this->controller->redirect('/' . Inflector::underscore($this->controller->viewPath));
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__("No id set for %s::edit()", true), Inflector::humanize($this->modelKey)),
|
||||
'/' . Inflector::underscore($this->controller->viewPath));
|
||||
}
|
||||
$this->controller->data = $this->ScaffoldModel->read();
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames($this->controller->data));
|
||||
$this->controller->set('data', $this->controller->data);
|
||||
} else {
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
||||
}
|
||||
return $this->__scaffoldForm($formAction);
|
||||
}
|
||||
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
||||
|
@ -430,16 +420,16 @@ class Scaffold extends Object {
|
|||
$this->__scaffoldIndex($params);
|
||||
break;
|
||||
case 'add':
|
||||
$this->__scaffoldForm($params, 'add');
|
||||
$this->__scaffoldSave($params, 'add');
|
||||
break;
|
||||
case 'edit':
|
||||
$this->__scaffoldForm($params, 'edit');
|
||||
$this->__scaffoldSave($params, 'edit');
|
||||
break;
|
||||
case 'create':
|
||||
$this->__scaffoldSave($params, 'create');
|
||||
$this->__scaffoldSave($params, 'add');
|
||||
break;
|
||||
case 'update':
|
||||
$this->__scaffoldSave($params, 'update');
|
||||
$this->__scaffoldSave($params, 'edit');
|
||||
break;
|
||||
case 'delete':
|
||||
$this->__scaffoldDelete($params);
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.scaffolds
|
||||
* @since CakePHP v 0.10.0.1076
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2>New <?php echo $humanSingularName?></h2>
|
||||
<?php
|
||||
echo $form->create($modelClass);
|
||||
echo $form->inputs($fieldNames);
|
||||
echo $form->submit(__('Add', true)); ?>
|
||||
</form>
|
||||
<ul class='actions'>
|
||||
<?php echo "<li>".$html->link(__('List ', true).$humanPluralName, array('action' => 'index'))."</li>"; ?>
|
||||
<?php
|
||||
foreach($fieldNames as $field => $value) {
|
||||
if(isset($value['foreignKey'])) {
|
||||
echo "<li>".$html->link(__("View ", true).Inflector::humanize($value['controller']), $path . Inflector::underscore($value['controller'])."/index/")."</li>";
|
||||
echo "<li>".$html->link(__("Add ", true).Inflector::humanize($value['modelKey']), $path . Inflector::underscore($value['controller'])."/add/")."</li>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
Loading…
Reference in a new issue