HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
controller.php
Go to the documentation of this file.
1 <?php
7 ?>
8 <?php echo "<?php\n"; ?>
9 
10 class <?php echo $this->controllerClass; ?> extends <?php echo $this->baseControllerClass . "\n"; ?>
11 {
16 public $layout='//layouts/column2';
17 
21 public function filters()
22 {
23 return array(
24 'accessControl', // perform access control for CRUD operations
25 );
26 }
27 
33 public function accessRules()
34 {
35 return array(
36 array('allow', // allow all users to perform 'index' and 'view' actions
37 'actions'=>array('index','view'),
38 'users'=>array('*'),
39 ),
40 array('allow', // allow authenticated user to perform 'create' and 'update' actions
41 'actions'=>array('create','update'),
42 'users'=>array('@'),
43 ),
44 array('allow', // allow admin user to perform 'admin' and 'delete' actions
45 'actions'=>array('admin','delete'),
46 'users'=>array('admin'),
47 ),
48 array('deny', // deny all users
49 'users'=>array('*'),
50 ),
51 );
52 }
53 
58 public function actionView($id)
59 {
60 $this->render('view',array(
61 'model'=>$this->loadModel($id),
62 ));
63 }
64 
69 public function actionCreate()
70 {
71 $model=new <?php echo $this->modelClass; ?>;
72 
73 // Uncomment the following line if AJAX validation is needed
74 // $this->performAjaxValidation($model);
75 
76 if(isset($_POST['<?php echo $this->modelClass; ?>']))
77 {
78 $model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
79 if($model->save())
80 $this->redirect(array('view','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>));
81 }
82 
83 $this->render('create',array(
84 'model'=>$model,
85 ));
86 }
87 
93 public function actionUpdate($id)
94 {
95 $model=$this->loadModel($id);
96 
97 // Uncomment the following line if AJAX validation is needed
98 // $this->performAjaxValidation($model);
99 
100 if(isset($_POST['<?php echo $this->modelClass; ?>']))
101 {
102 $model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
103 if($model->save())
104 $this->redirect(array('view','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>));
105 }
106 
107 $this->render('update',array(
108 'model'=>$model,
109 ));
110 }
111 
117 public function actionDelete($id)
118 {
119 if(Yii::app()->request->isPostRequest)
120 {
121 // we only allow deletion via POST request
122 $this->loadModel($id)->delete();
123 
124 // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
125 if(!isset($_GET['ajax']))
126 $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
127 }
128 else
129 throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
130 }
131 
135 public function actionIndex()
136 {
137 $dataProvider=new CActiveDataProvider('<?php echo $this->modelClass; ?>');
138 $this->render('index',array(
139 'dataProvider'=>$dataProvider,
140 ));
141 }
142 
146 public function actionAdmin()
147 {
148 $model=new <?php echo $this->modelClass; ?>('search');
149 $model->unsetAttributes(); // clear any default values
150 if(isset($_GET['<?php echo $this->modelClass; ?>']))
151 $model->attributes=$_GET['<?php echo $this->modelClass; ?>'];
152 
153 $this->render('admin',array(
154 'model'=>$model,
155 ));
156 }
157 
163 public function loadModel($id)
164 {
165 $model=<?php echo $this->modelClass; ?>::model()->findByPk($id);
166 if($model===null)
167 throw new CHttpException(404,'The requested page does not exist.');
168 return $model;
169 }
170 
175 protected function performAjaxValidation($model)
176 {
177 if(isset($_POST['ajax']) && $_POST['ajax']==='<?php echo $this->class2id($this->modelClass); ?>-form')
178 {
179 echo CActiveForm::validate($model);
180 Yii::app()->end();
181 }
182 }
183 }