Removing performAction from the scaffold generator until we can have proper unit...
[akelos.git] / lib / utils / generators / scaffold / templates / controller.php
blobc0cb2788a764e33c2bd133712efd2ee5f617637c
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 $options = $this->pagination_helper->getFindOptions($this-><?php echo $model_name?>);
26 $this-><?php echo $plural_name?> =& $this-><?php echo $model_name?>->find('all', $options);
29 function show()
30 {<?php if($model_name != $controller_name){ ?>
32 $this-><?php echo $singular_name?> =& $this-><?php echo $model_name?>->find(@$this->params['id']);<?php } ?>
36 function add()
38 if(!empty($this->params['<?php echo $singular_name?>'])){
39 $this-><?php echo $model_name?>->setAttributes($this->params['<?php echo $singular_name?>']);
40 if ($this->Request->isPost() && $this-><?php echo $model_name?>->save()){
41 $this->flash['notice'] = $this->t('<?php echo $model_name?> was successfully created.');
42 $this->redirectTo(array('action' => 'show', 'id' => $this-><?php echo $model_name?>->getId()));
46 <?php if($model_name != $controller_name){ ?>
48 function edit()
50 if(!empty($this->params['id'])){
51 if(empty($this-><?php echo $singular_name?>->id) || $this-><?php echo $singular_name?>->id != $this->params['id']){
52 $this-><?php echo $singular_name?> =& $this-><?php echo $model_name?>->find($this->params['id']);
54 }else{
55 $this->redirectToAction('listing');
58 if(!empty($this->params['<?php echo $singular_name?>'])){
59 $this-><?php echo $singular_name?>->setAttributes($this->params['<?php echo $singular_name?>']);
60 if($this->Request->isPost() && $this-><?php echo $singular_name?>->save()){
61 $this->flash['notice'] = $this->t('<?php echo $model_name?> was successfully updated.');
62 $this->redirectTo(array('action' => 'show', 'id' => $this-><?php echo $singular_name?>->getId()));
66 <?php } else { ?>
68 function edit()
70 if (empty($this->params['id'])){
71 $this->redirectToAction('listing');
73 if(!empty($this->params['<?php echo $singular_name?>']) && !empty($this->params['id'])){
74 $this-><?php echo $singular_name?>->setAttributes($this->params['<?php echo $singular_name?>']);
75 if($this->Request->isPost() && $this-><?php echo $singular_name?>->save()){
76 $this->flash['notice'] = $this->t('<?php echo $model_name?> was successfully updated.');
77 $this->redirectTo(array('action' => 'show', 'id' => $this-><?php echo $singular_name?>->getId()));
81 <?php } ?>
83 function destroy()
85 if(!empty($this->params['id'])){
86 $this-><?php echo $singular_name?> =& $this-><?php echo $model_name?>->find($this->params['id']);
87 if($this->Request->isPost()){
88 $this-><?php echo $singular_name?>->destroy();
89 $this->redirectTo(array('action' => 'listing'));