1 <?php
2
3 class UserController extends Controller
4 {
5 /**
6 * @var CActiveRecord the currently loaded data model instance.
7 */
8 private $_model;
9
10 /**
11 * @return array action filters
12 */
13 public function filters()
14 {
15 return CMap::mergeArray(parent::filters(),array(
16 'accessControl', // perform access control for CRUD operations
17 ));
18 }
19 /**
20 * Specifies the access control rules.
21 * This method is used by the 'accessControl' filter.
22 * @return array access control rules
23 */
24 public function accessRules()
25 {
26 return array(
27 array('allow', // allow all users to perform 'index' and 'view' actions
28 'actions'=>array('index','view'),
29 'users'=>array('*'),
30 ),
31 array('deny', // deny all users
32 'users'=>array('*'),
33 ),
34 );
35 }
36
37 /**
38 * Displays a particular model.
39 */
40 public function actionView()
41 {
42 $model = $this->loadModel();
43 $this->render('view',array(
44 'model'=>$model,
45 ));
46 }
47
48 /**
49 * Lists all models.
50 */
51 public function actionIndex()
52 {
53 $dataProvider=new CActiveDataProvider('User', array(
54 'criteria'=>array(
55 'condition'=>'status>'.User::STATUS_BANNED,
56 ),
57
58 'pagination'=>array(
59 'pageSize'=>Yii::app()->controller->module->user_page_size,
60 ),
61 ));
62
63 $this->render('index',array(
64 'dataProvider'=>$dataProvider,
65 ));
66 }
67
68 /**
69 * Returns the data model based on the primary key given in the GET variable.
70 * If the data model is not found, an HTTP exception will be raised.
71 */
72 public function loadModel()
73 {
74 if($this->_model===null)
75 {
76 if(isset($_GET['id']))
77 $this->_model=User::model()->findbyPk($_GET['id']);
78 if($this->_model===null)
79 throw new CHttpException(404,'The requested page does not exist.');
80 }
81 return $this->_model;
82 }
83
84
85 /**
86 * Returns the data model based on the primary key given in the GET variable.
87 * If the data model is not found, an HTTP exception will be raised.
88 * @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable
89 */
90 public function loadUser($id=null)
91 {
92 if($this->_model===null)
93 {
94 if($id!==null || isset($_GET['id']))
95 $this->_model=User::model()->findbyPk($id!==null ? $id : $_GET['id']);
96 if($this->_model===null)
97 throw new CHttpException(404,'The requested page does not exist.');
98 }
99 return $this->_model;
100 }
101 }
102