Removing performAction from the scaffold generator until we can have proper unit...
[akelos.git] / lib / utils / generators / scaffold / sintags_templates / controller.php
blobbc0711668bb5b97c79f7263b0e9e4b8fca2503f6
1 <?php echo '<?php'?>
4 class <?php echo $controller_class_name?> extends ApplicationController
6 <?php
7 if($model_name != $controller_name){ // if equal will be handled by the Akelos directly
8 echo " var \$models = '$singular_name';\n\n";
11 function index()
13 $this->redirectToAction('listing');
16 <?php foreach((array)@$actions as $action) :?>
17 function <?php echo $action?>()
21 <?php endforeach; ?>
22 function listing()
24 $this-><?php echo $singular_name?>_pages = $this->pagination_helper->getPaginator($this-><?php echo $model_name?>, array('items_per_page' => 10));
25 $this-><?php echo $plural_name?> = $this-><?php echo $model_name?>->find('all', $this->pagination_helper->getFindOptions($this-><?php echo $model_name?>));
28 function show()
30 $this-><?php echo $singular_name?> = $this-><?php echo $model_name?>->find(@$this->params['id']);
33 function add()
35 if(!empty($this->params['<?php echo $singular_name?>'])){
36 $this-><?php echo $model_name?>->setAttributes($this->params['<?php echo $singular_name?>']);
37 if ($this->Request->isPost() && $this-><?php echo $model_name?>->save()){
38 $this->flash['notice'] = $this->t('<?php echo $model_name?> was successfully created.');
39 $this->redirectTo(array('action' => 'show', 'id' => $this-><?php echo $model_name?>->getId()));
43 <?php if($model_name != $controller_name){ ?>
45 function edit()
47 if(!empty($this->params['id'])){
48 if(empty($this-><?php echo $singular_name?>->id) || $this-><?php echo $singular_name?>->id != $this->params['id']){
49 $this-><?php echo $singular_name?> =& $this-><?php echo $model_name?>->find($this->params['id']);
51 }else{
52 $this->redirectToAction('listing');
55 if(!empty($this->params['<?php echo $singular_name?>'])){
56 $this-><?php echo $singular_name?>->setAttributes($this->params['<?php echo $singular_name?>']);
57 if($this->Request->isPost() && $this-><?php echo $singular_name?>->save()){
58 $this->flash['notice'] = $this->t('<?php echo $model_name?> was successfully updated.');
59 $this->redirectTo(array('action' => 'show', 'id' => $this-><?php echo $singular_name?>->getId()));
63 <?php } else { ?>
65 function edit()
67 if (empty($this->params['id'])){
68 $this->redirectToAction('listing');
70 if(!empty($this->params['<?php echo $singular_name?>']) && !empty($this->params['id'])){
71 $this-><?php echo $singular_name?>->setAttributes($this->params['<?php echo $singular_name?>']);
72 if($this->Request->isPost() && $this-><?php echo $singular_name?>->save()){
73 $this->flash['notice'] = $this->t('<?php echo $model_name?> was successfully updated.');
74 $this->redirectTo(array('action' => 'show', 'id' => $this-><?php echo $singular_name?>->getId()));
78 <?php } ?>
80 function destroy()
82 if(!empty($this->params['id'])){
83 $this-><?php echo $singular_name?> = $this-><?php echo $model_name?>->find($this->params['id']);
84 if($this->Request->isPost()){
85 $this-><?php echo $singular_name?>->destroy();
86 $this->redirectTo(array('action' => 'listing'));