2009-07-01 00:24:20 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Bake Template for Controller action generation.
|
|
|
|
*
|
2010-10-03 12:38:58 -04:00
|
|
|
* PHP 5
|
2009-07-01 00:24:20 -04:00
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-10-25 07:58:22 +11:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-07-01 00:24:20 -04:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-10-25 07:58:22 +11:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 17:03:03 -05:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 13:57:20 -05:00
|
|
|
* @package cake.console.libs.template.objects
|
2009-07-01 00:24:20 -04:00
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
?>
|
|
|
|
|
2011-01-19 22:22:50 -02:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 16:46:01 +10:00
|
|
|
public function <?php echo $admin ?>index() {
|
2009-07-01 00:24:20 -04:00
|
|
|
$this-><?php echo $currentModelName ?>->recursive = 0;
|
|
|
|
$this->set('<?php echo $pluralName ?>', $this->paginate());
|
|
|
|
}
|
|
|
|
|
2011-01-19 22:22:50 -02:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>view method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 16:46:01 +10:00
|
|
|
public function <?php echo $admin ?>view($id = null) {
|
2010-12-12 12:37:02 -05:00
|
|
|
$this-><?php echo $currentModelName; ?>->id = $id;
|
|
|
|
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
2009-07-01 00:24:20 -04:00
|
|
|
}
|
|
|
|
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
<?php $compact = array(); ?>
|
2011-01-19 22:22:50 -02:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>add method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 16:46:01 +10:00
|
|
|
public function <?php echo $admin ?>add() {
|
2010-11-07 01:08:02 -04:00
|
|
|
if ($this->request->is('post')) {
|
2009-07-01 00:24:20 -04:00
|
|
|
$this-><?php echo $currentModelName; ?>->create();
|
2010-11-07 01:08:02 -04:00
|
|
|
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php if ($wannaUseSession): ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
|
2009-07-01 00:24:20 -04:00
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
<?php else: ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php endif; ?>
|
|
|
|
} else {
|
|
|
|
<?php if ($wannaUseSession): ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php endif; ?>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<?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-19 22:22:50 -02:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>edit method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 16:46:01 +10:00
|
|
|
public function <?php echo $admin; ?>edit($id = null) {
|
2010-12-12 12:37:02 -05:00
|
|
|
$this-><?php echo $currentModelName; ?>->id = $id;
|
|
|
|
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
2009-07-01 00:24:20 -04:00
|
|
|
}
|
2010-12-14 22:09:29 -05:00
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
2010-11-07 01:08:02 -04:00
|
|
|
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php if ($wannaUseSession): ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
|
2009-07-01 00:24:20 -04:00
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
<?php else: ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php endif; ?>
|
|
|
|
} else {
|
|
|
|
<?php if ($wannaUseSession): ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php endif; ?>
|
|
|
|
}
|
2010-12-12 12:37:02 -05:00
|
|
|
} else {
|
2010-12-27 15:34:56 -05:00
|
|
|
$this->request->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
|
2009-07-01 00:24:20 -04: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-19 22:22:50 -02:00
|
|
|
/**
|
|
|
|
* <?php echo $admin ?>delete method
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 16:46:01 +10:00
|
|
|
public function <?php echo $admin; ?>delete($id = null) {
|
2010-10-30 21:58:42 -02:00
|
|
|
if (!$this->request->is('post')) {
|
2010-10-30 23:13:54 -02:00
|
|
|
throw new MethodNotAllowedException();
|
2010-10-30 21:58:42 -02:00
|
|
|
}
|
2010-12-12 12:37:02 -05:00
|
|
|
$this-><?php echo $currentModelName; ?>->id = $id;
|
|
|
|
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
2009-07-01 00:24:20 -04:00
|
|
|
}
|
2010-12-12 12:37:02 -05:00
|
|
|
if ($this-><?php echo $currentModelName; ?>->delete()) {
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php if ($wannaUseSession): ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
|
2009-07-01 00:24:20 -04:00
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
<?php else: ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php endif; ?>
|
|
|
|
}
|
|
|
|
<?php if ($wannaUseSession): ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php else: ?>
|
2010-05-02 17:53:42 -04:00
|
|
|
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
|
2009-07-01 00:24:20 -04:00
|
|
|
<?php endif; ?>
|
|
|
|
$this->redirect(array('action' => 'index'));
|
2009-07-24 21:18:37 +02:00
|
|
|
}
|