2009-07-01 04:24:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Bake Template for Controller action generation.
|
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2009-07-01 04:24:20 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-07-01 04:24:20 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-10-15 18:26:48 +00:00
|
|
|
* @package Cake.Console.Templates.default.actions
|
2009-07-01 04:24:20 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2009-07-01 04:24:20 +00:00
|
|
|
*/
|
|
|
|
?>
|
|
|
|
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public function <?php echo $admin ?>index() {
|
2009-07-01 04:24:20 +00:00
|
|
|
$this-><?php echo $currentModelName ?>->recursive = 0;
|
2013-07-20 14:59:39 +00:00
|
|
|
$this->set('<?php echo $pluralName ?>', $this->Paginator->paginate());
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>view method
|
|
|
|
*
|
2012-05-09 22:28:02 +00:00
|
|
|
* @throws NotFoundException
|
2011-01-20 00:22:50 +00:00
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public function <?php echo $admin ?>view($id = null) {
|
2012-09-30 07:38:57 +00:00
|
|
|
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
|
2010-12-12 17:37:02 +00:00
|
|
|
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
2012-09-30 07:38:57 +00:00
|
|
|
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
|
|
|
|
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->find('first', $options));
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
<?php $compact = array(); ?>
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>add method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public function <?php echo $admin ?>add() {
|
2012-08-25 12:43:12 +00:00
|
|
|
if ($this->request->is('post')) {
|
2009-07-01 04:24:20 +00:00
|
|
|
$this-><?php echo $currentModelName; ?>->create();
|
2010-11-07 05:08:02 +00:00
|
|
|
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php if ($wannaUseSession): ?>
|
2015-08-16 23:01:23 +00:00
|
|
|
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
2013-07-28 21:44:07 +00:00
|
|
|
return $this->redirect(array('action' => 'index'));
|
2013-08-09 21:06:15 +00:00
|
|
|
} else {
|
2015-08-16 23:01:23 +00:00
|
|
|
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php else: ?>
|
2013-08-09 21:06:15 +00:00
|
|
|
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php endif; ?>
|
2013-08-08 19:07:46 +00:00
|
|
|
}
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
|
|
|
<?php
|
|
|
|
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
|
|
|
|
foreach ($modelObj->{$assoc} as $associationName => $relation):
|
|
|
|
if (!empty($associationName)):
|
|
|
|
$otherModelName = $this->_modelName($associationName);
|
|
|
|
$otherPluralName = $this->_pluralName($associationName);
|
|
|
|
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
|
|
|
|
$compact[] = "'{$otherPluralName}'";
|
|
|
|
endif;
|
|
|
|
endforeach;
|
|
|
|
endforeach;
|
|
|
|
if (!empty($compact)):
|
|
|
|
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
|
|
|
|
endif;
|
|
|
|
?>
|
|
|
|
}
|
|
|
|
|
|
|
|
<?php $compact = array(); ?>
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>edit method
|
|
|
|
*
|
2012-05-09 22:28:02 +00:00
|
|
|
* @throws NotFoundException
|
2011-01-20 00:22:50 +00:00
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public function <?php echo $admin; ?>edit($id = null) {
|
2012-09-30 07:38:57 +00:00
|
|
|
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
|
2010-12-12 17:37:02 +00:00
|
|
|
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
2013-09-12 22:09:31 +00:00
|
|
|
if ($this->request->is(array('post', 'put'))) {
|
2010-11-07 05:08:02 +00:00
|
|
|
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php if ($wannaUseSession): ?>
|
2015-08-16 23:01:23 +00:00
|
|
|
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
2013-07-28 21:44:07 +00:00
|
|
|
return $this->redirect(array('action' => 'index'));
|
2013-08-09 21:06:15 +00:00
|
|
|
} else {
|
2015-08-16 23:01:23 +00:00
|
|
|
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php else: ?>
|
2013-08-08 19:07:46 +00:00
|
|
|
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php endif; ?>
|
2013-08-08 19:07:46 +00:00
|
|
|
}
|
2010-12-12 17:37:02 +00:00
|
|
|
} else {
|
2012-09-30 07:38:57 +00:00
|
|
|
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
|
|
|
|
$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
|
|
|
<?php
|
|
|
|
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
|
|
|
|
foreach ($modelObj->{$assoc} as $associationName => $relation):
|
|
|
|
if (!empty($associationName)):
|
|
|
|
$otherModelName = $this->_modelName($associationName);
|
|
|
|
$otherPluralName = $this->_pluralName($associationName);
|
|
|
|
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
|
|
|
|
$compact[] = "'{$otherPluralName}'";
|
|
|
|
endif;
|
|
|
|
endforeach;
|
|
|
|
endforeach;
|
|
|
|
if (!empty($compact)):
|
|
|
|
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
|
|
|
|
endif;
|
|
|
|
?>
|
|
|
|
}
|
|
|
|
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>delete method
|
|
|
|
*
|
2012-05-09 22:28:02 +00:00
|
|
|
* @throws NotFoundException
|
2011-01-20 00:22:50 +00:00
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public function <?php echo $admin; ?>delete($id = null) {
|
2010-12-12 17:37:02 +00:00
|
|
|
$this-><?php echo $currentModelName; ?>->id = $id;
|
|
|
|
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
2014-02-10 12:26:57 +00:00
|
|
|
$this->request->allowMethod('post', 'delete');
|
2010-12-12 17:37:02 +00:00
|
|
|
if ($this-><?php echo $currentModelName; ?>->delete()) {
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php if ($wannaUseSession): ?>
|
2015-08-16 23:01:23 +00:00
|
|
|
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
|
2013-08-09 21:06:15 +00:00
|
|
|
} else {
|
2015-08-16 23:01:23 +00:00
|
|
|
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
2013-08-09 21:06:15 +00:00
|
|
|
return $this->redirect(array('action' => 'index'));
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php else: ?>
|
2013-08-09 21:06:15 +00:00
|
|
|
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'), array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
|
|
}
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php endif; ?>
|
2012-05-09 22:28:02 +00:00
|
|
|
}
|