10
10
<?php echo "<?php\n"; ?>
12
class <?php echo $controllerClass; ?> extends CController
12
class <?php echo $controllerClass; ?> extends Controller
14
14
const PAGE_SIZE=10;
17
* @var string specifies the default action to be 'list'.
19
public $defaultAction='list';
22
17
* @var CActiveRecord the currently loaded data model instance.
41
36
public function accessRules()
44
array('allow', // allow all users to perform 'list' and 'show' actions
45
'actions'=>array('list','show'),
39
array('allow', // allow all users to perform 'index' and 'view' actions
40
'actions'=>array('index','view'),
46
41
'users'=>array('*'),
48
43
array('allow', // allow authenticated user to perform 'create' and 'update' actions
63
* Shows a particular model.
58
* Displays a particular model.
65
public function actionShow()
60
public function actionView()
67
$this->render('show',array('model'=>$this->load<?php echo $modelClass; ?>()));
62
$this->render('view',array(
63
'model'=>$this->loadModel(),
71
68
* Creates a new model.
72
* If creation is successful, the browser will be redirected to the 'show' page.
69
* If creation is successful, the browser will be redirected to the 'view' page.
74
71
public function actionCreate()
79
76
$model->attributes=$_POST['<?php echo $modelClass; ?>'];
81
$this->redirect(array('show','id'=>$model-><?php echo $ID; ?>));
78
$this->redirect(array('view','id'=>$model-><?php echo $ID; ?>));
83
$this->render('create',array('model'=>$model));
81
$this->render('create',array(
87
87
* Updates a particular model.
88
* If update is successful, the browser will be redirected to the 'show' page.
88
* If update is successful, the browser will be redirected to the 'view' page.
90
90
public function actionUpdate()
92
$model=$this->load<?php echo $modelClass; ?>();
92
$model=$this->loadModel();
93
93
if(isset($_POST['<?php echo $modelClass; ?>']))
95
95
$model->attributes=$_POST['<?php echo $modelClass; ?>'];
97
$this->redirect(array('show','id'=>$model-><?php echo $ID; ?>));
97
$this->redirect(array('view','id'=>$model-><?php echo $ID; ?>));
99
$this->render('update',array('model'=>$model));
100
$this->render('update',array(
103
106
* Deletes a particular model.
104
* If deletion is successful, the browser will be redirected to the 'list' page.
107
* If deletion is successful, the browser will be redirected to the 'index' page.
106
109
public function actionDelete()
108
111
if(Yii::app()->request->isPostRequest)
110
113
// we only allow deletion via POST request
111
$this->load<?php echo $modelClass; ?>()->delete();
112
$this->redirect(array('list'));
114
$this->loadModel()->delete();
116
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
117
if(!isset($_POST['ajax']))
118
$this->redirect(array('index'));
115
121
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
119
125
* Lists all models.
121
public function actionList()
127
public function actionIndex()
123
$criteria=new CDbCriteria;
125
$pages=new CPagination(<?php echo $modelClass; ?>::model()->count($criteria));
126
$pages->pageSize=self::PAGE_SIZE;
127
$pages->applyLimit($criteria);
129
$models=<?php echo $modelClass; ?>::model()->findAll($criteria);
131
$this->render('list',array(
129
$dataProvider=new CActiveDataProvider('<?php echo $modelClass; ?>', array(
131
'pageSize'=>self::PAGE_SIZE,
135
$this->render('index',array(
136
'dataProvider'=>$dataProvider,
140
143
public function actionAdmin()
142
$this->processAdminCommand();
144
$criteria=new CDbCriteria;
146
$pages=new CPagination(<?php echo $modelClass; ?>::model()->count($criteria));
147
$pages->pageSize=self::PAGE_SIZE;
148
$pages->applyLimit($criteria);
150
$sort=new CSort('<?php echo $modelClass; ?>');
151
$sort->applyOrder($criteria);
153
$models=<?php echo $modelClass; ?>::model()->findAll($criteria);
145
$dataProvider=new CActiveDataProvider('<?php echo $modelClass; ?>', array(
147
'pageSize'=>self::PAGE_SIZE,
155
151
$this->render('admin',array(
152
'dataProvider'=>$dataProvider,
163
157
* Returns the data model based on the primary key given in the GET variable.
164
158
* If the data model is not found, an HTTP exception will be raised.
165
* @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable
167
public function load<?php echo $modelClass; ?>($id=null)
160
public function loadModel()
169
162
if($this->_model===null)
171
if($id!==null || isset($_GET['id']))
172
$this->_model=<?php echo $modelClass; ?>::model()->findbyPk($id!==null ? $id : $_GET['id']);
164
if(isset($_GET['id']))
165
$this->_model=<?php echo $modelClass; ?>::model()->findbyPk($_GET['id']);
173
166
if($this->_model===null)
174
167
throw new CHttpException(404,'The requested page does not exist.');
176
169
return $this->_model;
180
* Executes any command triggered on the admin page.
182
protected function processAdminCommand()
184
if(isset($_POST['command'], $_POST['id']) && $_POST['command']==='delete')
186
$this->load<?php echo $modelClass; ?>($_POST['id'])->delete();
187
// reload the current page to avoid duplicated delete actions