EliteConf
 All Data Structures Namespaces Files Functions Variables Pages
MessageController.php
Go to the documentation of this file.
1 <?php
2 
8 {
13  public $layout='//layouts/column2';
14 
18  public function filters()
19  {
20  return array(
21  'accessControl', // perform access control for CRUD operations
22  'postOnly + delete', // we only allow deletion via POST request
23  );
24  }
25 
31  public function accessRules()
32  {
33  return array(
34  array('allow', // allow all users to perform 'index' and 'view' actions
35  'actions'=>array('index','view'),
36  'users'=>array('*'),
37  ),
38  array('allow', // allow authenticated user to perform 'create' and 'update' actions
39  'actions'=>array('create','update'),
40  'users'=>array('@'),
41  ),
42  array('allow', // allow admin user to perform 'admin' and 'delete' actions
43  'actions'=>array('admin','delete'),
44  'users'=>array('admin'),
45  ),
46  array('deny', // deny all users
47  'users'=>array('*'),
48  ),
49  );
50  }
51 
56  public function actionView($id)
57  {
58  $this->render('view',array(
59  'model'=>$this->loadModel($id),
60  ));
61  }
62 
67  public function actionCreate()
68  {
69  $model=new Message;
70 
71  // Uncomment the following line if AJAX validation is needed
72  // $this->performAjaxValidation($model);
73 
74  if(isset($_POST['Message']))
75  {
76  $model->attributes=$_POST['Message'];
77  if($model->save())
78  $this->redirect(array('view','id'=>$model->id));
79  }
80 
81  $this->render('create',array(
82  'model'=>$model,
83  ));
84  }
85 
91  public function actionUpdate($id)
92  {
93  $model=$this->loadModel($id);
94 
95  // Uncomment the following line if AJAX validation is needed
96  // $this->performAjaxValidation($model);
97 
98  if(isset($_POST['Message']))
99  {
100  $model->attributes=$_POST['Message'];
101  if($model->save())
102  $this->redirect(array('view','id'=>$model->id));
103  }
104 
105  $this->render('update',array(
106  'model'=>$model,
107  ));
108  }
109 
115  public function actionDelete($id)
116  {
117  $this->loadModel($id)->delete();
118 
119  // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
120  if(!isset($_GET['ajax']))
121  $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
122  }
123 
127  public function actionIndex()
128  {
129  $dataProvider=new CActiveDataProvider('Message');
130  $this->render('index',array(
131  'dataProvider'=>$dataProvider,
132  ));
133  }
134 
138  public function actionAdmin()
139  {
140  $model=new Message('search');
141  $model->unsetAttributes(); // clear any default values
142  if(isset($_GET['Message']))
143  $model->attributes=$_GET['Message'];
144 
145  $this->render('admin',array(
146  'model'=>$model,
147  ));
148  }
149 
155  public function loadModel($id)
156  {
157  $model=Message::model()->findByPk($id);
158  if($model===null)
159  throw new CHttpException(404,'The requested page does not exist.');
160  return $model;
161  }
162 
167  protected function performAjaxValidation($model)
168  {
169  if(isset($_POST['ajax']) && $_POST['ajax']==='message-form')
170  {
171  echo CActiveForm::validate($model);
172  Yii::app()->end();
173  }
174  }
175 }