EliteConf
 All Data Structures Namespaces Files Functions Variables Pages
UsersController.php
Go to the documentation of this file.
1 <?php
2 
3 
5 {
10  public $layout='//layouts/column2';
11 
15  public function filters()
16  {
17  return array(
18  'accessControl', // perform access control for CRUD operations
19  'postOnly + delete', // we only allow deletion via POST request
20  );
21  }
22 
28  public function accessRules()
29  {
30  return array(
31  array('allow', // allow all users to perform 'index' and 'view' actions
32  'actions'=>array('index','view'),
33  'users'=>array('*'),
34  ),
35  array('allow', // allow authenticated user to perform 'create' and 'update' actions
36  'actions'=>array('create','update'),
37  'users'=>array('@'),
38  ),
39  array('allow', // allow admin user to perform 'admin' and 'delete' actions
40  'actions'=>array('admin','delete'),
41  'users'=>array('admin'),
42  ),
43  array('deny', // deny all users
44  'users'=>array('*'),
45  ),
46  );
47  }
48 
53  public function actionView($id)
54  {
55  $this->render('view',array(
56  'model'=>$this->loadModel($id),
57  ));
58  }
59 
64  public function actionCreate()
65  {
66  $model=new Users;
67 
68  // Uncomment the following line if AJAX validation is needed
69  // $this->performAjaxValidation($model);
70 
71  if(isset($_POST['Users']))
72  {
73  $model->attributes=$_POST['Users'];
74  if($model->save())
75  $this->redirect(array('view','id'=>$model->userid));
76  }
77 
78  $this->render('create',array(
79  'model'=>$model,
80  ));
81  }
82 
88  public function actionUpdate($id)
89  {
90  $model=$this->loadModel($id);
91 
92  // Uncomment the following line if AJAX validation is needed
93  // $this->performAjaxValidation($model);
94 
95  if(isset($_POST['Users']))
96  {
97  $model->attributes=$_POST['Users'];
98  if($model->save())
99  $this->redirect(array('view','id'=>$model->userid));
100  }
101 
102  $this->render('update',array(
103  'model'=>$model,
104  ));
105  }
106 
112  public function actionDelete($id)
113  {
114  $this->loadModel($id)->delete();
115 
116  // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
117  if(!isset($_GET['ajax']))
118  $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
119  }
120 
124  public function actionIndex()
125  {
126  $dataProvider=new CActiveDataProvider('Users');
127  $this->render('index',array(
128  'dataProvider'=>$dataProvider,
129  ));
130  }
131 
135  public function actionAdmin()
136  {
137  $model=new Users('search');
138  $model->unsetAttributes(); // clear any default values
139  if(isset($_GET['Users']))
140  $model->attributes=$_GET['Users'];
141 
142  $this->render('admin',array(
143  'model'=>$model,
144  ));
145  }
146 
152  public function loadModel($id)
153  {
154  $model=Users::model()->findByPk($id);
155  if($model===null)
156  throw new CHttpException(404,'The requested page does not exist.');
157  return $model;
158  }
159 
164  protected function performAjaxValidation($model)
165  {
166  if(isset($_POST['ajax']) && $_POST['ajax']==='users-form')
167  {
168  echo CActiveForm::validate($model);
169  Yii::app()->end();
170  }
171  }
172 }