UserController
| Package | application.controllers.UserController |
|---|---|
| Inheritance | class UserController » Controller » SBaseController » CController » CBaseController » CComponent |
| Views | admin, create, index, update, view |
| Source Code | app/controllers/UserController.php |
UserController defines user actions, communicates between models and views.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| action | CAction | the action currently being executed, null if no active action. | CController |
| back | Controller | ||
| breadcrumbs | array | the breadcrumbs of the current page. | Controller |
| cachingStack | CStack | stack of COutputCache objects | CController |
| clips | CMap | Returns the list of clips. | CController |
| defaultAction | string | specifies the default action to be 'list'. | UserController |
| id | string | ID of the controller | CController |
| layout | string | the default layout for the controller view. | Controller |
| menu | array | context menu items. | Controller |
| module | CWebModule | the module that this controller belongs to. | CController |
| pageTitle | string | the page title. | CController |
| roots | Controller | ||
| route | string | the route (module ID, controller ID and action ID) of the current request. | CController |
| selectedTA | Controller | ||
| tree | Controller | ||
| uniqueId | string | the controller ID that is prefixed with the module ID (if any). | CController |
| viewPath | string | Returns the directory containing view files for this controller. | CController |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __call() | Calls the named method which is not a class method. | CComponent |
| __construct() | CController | |
| __get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
| __isset() | Checks if a property value is null. | CComponent |
| __set() | Sets value of a component property. | CComponent |
| __unset() | Sets a component property to be null. | CComponent |
| accessRules() | Specifies the access control rules. | UserController |
| actionAdmin() | Manages all models. | UserController |
| actionCreate() | Creates a new model. | UserController |
| actionDelete() | Deletes a particular model. | UserController |
| actionIndex() | Lists all models. | UserController |
| actionUpdate() | Updates a particular model. | UserController |
| actionView() | Displays a particular model. | UserController |
| actions() | Returns a list of external action classes. | CController |
| asa() | Returns the named behavior object. | CComponent |
| attachBehavior() | Attaches a behavior to this component. | CComponent |
| attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
| attachEventHandler() | Attaches an event handler to an event. | CComponent |
| beginCache() | Begins fragment caching. | CBaseController |
| beginClip() | Begins recording a clip. | CBaseController |
| beginContent() | Begins the rendering of content that is to be decorated by the specified view. | CBaseController |
| beginWidget() | Creates a widget and executes it. | CBaseController |
| behaviors() | Returns a list of behaviors that this controller should behave as. | CController |
| canGetProperty() | Determines whether a property can be read. | CComponent |
| canSetProperty() | Determines whether a property can be set. | CComponent |
| clearPageStates() | Removes all page states. | CController |
| createAbsoluteUrl() | Creates an absolute URL for the specified action defined in this controller. | CController |
| createAction() | Creates the action instance based on the action name. | CController |
| createUrl() | Creates a relative URL for the specified action defined in this controller. | CController |
| createWidget() | Creates a widget and initializes it. | CBaseController |
| detachBehavior() | Detaches a behavior from the component. | CComponent |
| detachBehaviors() | Detaches all behaviors from the component. | CComponent |
| detachEventHandler() | Detaches an existing event handler. | CComponent |
| disableBehavior() | Disables an attached behavior. | CComponent |
| disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
| enableBehavior() | Enables an attached behavior. | CComponent |
| enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
| endCache() | Ends fragment caching. | CBaseController |
| endClip() | Ends recording a clip. | CBaseController |
| endContent() | Ends the rendering of content. | CBaseController |
| endWidget() | Ends the execution of the named widget. | CBaseController |
| evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
| filterAccessControl() | The filter method for 'accessControl' filter. | CController |
| filterAjaxOnly() | The filter method for 'ajaxOnly' filter. | CController |
| filterPostOnly() | The filter method for 'postOnly' filter. | CController |
| filters() | UserController | |
| forward() | Processes the request using another controller action. | CController |
| getAction() | Returns the action currently being executed, null if no active action. | CController |
| getCachingStack() | Returns stack of COutputCache objects | CController |
| getClips() | Returns the list of clips. | CController |
| getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
| getId() | Returns ID of the controller | CController |
| getLayoutFile() | Looks for the layout view script based on the layout name. | CController |
| getModule() | Returns the module that this controller belongs to. It returns null if the controller does not belong to any module | CController |
| getPageState() | Returns a persistent page state value. | CController |
| getPageTitle() | Returns the page title. Defaults to the controller name and the action name. | CController |
| getRoute() | Returns the route (module ID, controller ID and action ID) of the current request. | CController |
| getUniqueId() | Returns the controller ID that is prefixed with the module ID (if any). | CController |
| getViewFile() | Looks for the view file according to the given view name. | CController |
| getViewPath() | Returns the directory containing view files for this controller. | CController |
| hasEvent() | Determines whether an event is defined. | CComponent |
| hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
| hasProperty() | Determines whether a property is defined. | CComponent |
| init() | Initializes the controller. | CController |
| isCachingStackEmpty() | CController | |
| loadModel() | Returns the data model based on the primary key given in the GET variable. | UserController |
| log() | log message | UserController |
| missingAction() | Handles the request whose action is not recognized. | CController |
| paginate() | Generates pagination information. | CController |
| processDynamicOutput() | Postprocesses the dynamic output. | CController |
| processOutput() | Postprocesses the output generated by render(). | CController |
| raiseEvent() | Raises an event. | CComponent |
| recordCachingAction() | Records a method call when an output cache is in effect. | CController |
| redirect() | Redirects the browser to the specified URL or route (controller/action). | CController |
| refresh() | Refreshes the current page. | CController |
| render() | Renders a view with a layout. | CController |
| renderDynamic() | Renders dynamic content returned by the specified callback. | CController |
| renderDynamicInternal() | This method is internally used. | CController |
| renderFile() | Renders a view file. | CBaseController |
| renderInternal() | Renders a view file. | CBaseController |
| renderPartial() | Renders a view. | CController |
| renderPartialWithHisOwnClientScript() | Controller | |
| renderText() | Renders a static text string. | CController |
| resolveViewFile() | Finds a view file based on its name. | CController |
| run() | Runs the named action. | CController |
| runAction() | Runs the action after passing through all filters. | CController |
| runActionWithFilters() | Runs an action with the specified filters. | CController |
| setAction() | Sets the action currently being executed. | CController |
| setPageState() | Saves a persistent page state value. | CController |
| setPageTitle() | Sets the page title. | CController |
| widget() | Creates a widget and executes it. | CBaseController |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| afterAction() | This method is invoked right after an action is executed. | CController |
| allowedAccess() | The auth items that access is always allowed. Configured in srbac module's | SBaseController |
| beforeAction() | Checks if srbac access is granted for the current user | SBaseController |
| createActionFromMap() | Creates the action instance based on the action map. | CController |
| loadPageStates() | Loads page states from a hidden input. | CController |
| onUnauthorizedAccess() | SBaseController | |
| performAjaxValidation() | Performs the AJAX validation. | UserController |
| replaceDynamicOutput() | Replaces the dynamic content placeholders with actual content. | CController |
| savePageStates() | Saves page states as a base64 string. | CController |
Property Details
defaultAction
property
public string $defaultAction;
specifies the default action to be 'list'.
Method Details
accessRules()
method
|
public array accessRules()
| ||
| {return} | array | access control rules |
Source Code: app/controllers/UserController.php#39 (show)
public function accessRules()
{
$user = Yii::app()->user;
$aOwnProfile = 0;
if(isset($_GET['id'])&&$user!=null){
if($user->id==$_GET['id']){
$aOwnProfile = 1;
}
}
return array(
/*array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
*/
array('deny', //allow actions only for system admin and profile owner
'actions'=>array('update', 'temp'),
'expression'=>'!Yii::app()->user->checkAccess("UserAdmin") && !'.($aOwnProfile),
)
);
}
Specifies the access control rules. This method is used by the 'accessControl' filter.
actionAdmin()
method
|
public void actionAdmin()
|
Source Code: app/controllers/UserController.php#242 (show)
public function actionAdmin()
{
$model=new user('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['user']))
$model->attributes=$_GET['user'];
$this->render('admin',array(
'model'=>$model,
));
}
Manages all models.
actionCreate()
method
|
public void actionCreate()
|
Source Code: app/controllers/UserController.php#88 (show)
public function actionCreate()
{
$model=new user;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['user']))
{
$model->attributes=$_POST['user'];
$model->password = md5($_POST['user']['password']);
if($model->save()){
$ajxpHookFile = Yii::app()->params['ajPath']."/plugins/auth.remote/glueCode.php";
global $plugInAction, $result, $user, $AJXP_GLUE_GLOBALS;
$result = FALSE;
if (file_exists($ajxpHookFile))
{
//plugInAction = "addUser";
$AJXP_GLUE_GLOBALS["secret"] = "myprivatesecret";
$AJXP_GLUE_GLOBALS["plugInAction"] = "addUser";
$reset = $deleteData;
//$user = array("id"=>$model->id, "name"=>$model->username, "password"=>$model->password);
$AJXP_GLUE_GLOBALS["user"] = array("id"=>$model->id, "name"=>$model->username, "password"=>md5($model->password));
global $CURRENTPATH;
$CURRENTPATH = dirname($ajxpHookFile);
try{
require($ajxpHookFile);
}catch(Exception $e){
print $e;
}
spl_autoload_register(array('YiiBase','autoload'));
//$user = array();
$AJXP_GLUE_GLOBALS["user"] = array();
}
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('create',array(
'model'=>$model,
));
}
Creates a new model. If creation is successful, the browser will be redirected to the 'view' page.
actionDelete()
method
|
public void actionDelete()
|
Source Code: app/controllers/UserController.php#188 (show)
public function actionDelete()
{
$model=$this->loadModel();
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
if($model->delete()){
$ajxpHookFile = Yii::app()->params['ajPath']."/plugins/auth.remote/glueCode.php";
global $plugInAction, $result, $userName, $AJXP_GLUE_GLOBALS;
$result = FALSE;
if (file_exists($ajxpHookFile))
{
//$plugInAction = "delUser";
$AJXP_GLUE_GLOBALS["secret"] = "myprivatesecret";
$AJXP_GLUE_GLOBALS["plugInAction"] = "delUser";
$reset = $deleteData;
//$userName = $model->username;
$AJXP_GLUE_GLOBALS['userName']=$model->username;
global $CURRENTPATH;
$CURRENTPATH = dirname($ajxpHookFile);
try{
require($ajxpHookFile);
}catch(Exception $e){
print $e;
}
spl_autoload_register(array('YiiBase','autoload'));
//$userName = "";
$AJXP_GLUE_GLOBALS['userName']="";
}
}
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
Deletes a particular model. If deletion is successful, the browser will be redirected to the 'index' page.
actionIndex()
method
|
public void actionIndex()
|
Source Code: app/controllers/UserController.php#231 (show)
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('user');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
Lists all models.
actionUpdate()
method
|
public void actionUpdate()
|
Source Code: app/controllers/UserController.php#138 (show)
public function actionUpdate()
{
$model=$this->loadModel();
$password_ori = $model->password;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['user']))
{
$model->attributes=$_POST['user'];
if($password_ori!=$_POST['user']['password'])
$model->password = md5($_POST['user']['password']);
else
$model->password = $password_ori;
if($model->save()){
$ajxpHookFile = Yii::app()->params['ajPath']."/plugins/auth.remote/glueCode.php";
global $plugInAction, $result, $user, $AJXP_GLUE_GLOBALS;
$result = FALSE;
if (file_exists($ajxpHookFile))
{
//$plugInAction = "updateUser";
$AJXP_GLUE_GLOBALS["secret"] = "myprivatesecret";
$AJXP_GLUE_GLOBALS["plugInAction"] = "updateUser";
$reset = $deleteData;
//$user = array("id"=>$model->id, "name"=>$model->username, "password"=>$model->password);
$AJXP_GLUE_GLOBALS["user"] = array("id"=>$model->id, "name"=>$model->username, "password"=>$model->password);
global $CURRENTPATH;
$CURRENTPATH = dirname($ajxpHookFile);
try{
require($ajxpHookFile);
}catch(Exception $e){
print $e;
}
spl_autoload_register(array('YiiBase','autoload'));
//$user = array();
$AJXP_GLUE_GLOBALS["user"] = array();
}
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('update',array(
'model'=>$model,
));
}
Updates a particular model. If update is successful, the browser will be redirected to the 'view' page.
actionView()
method
|
public void actionView()
|
Source Code: app/controllers/UserController.php#77 (show)
public function actionView()
{
$this->render('view',array(
'model'=>$this->loadModel(),
));
}
Displays a particular model.
filters()
method
|
public array filters()
| ||
| {return} | array | action filters |
Source Code: app/controllers/UserController.php#27 (show)
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
loadModel()
method
|
public void loadModel()
|
Source Code: app/controllers/UserController.php#266 (show)
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
$this->_model=user::model()->findbyPk($_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
Returns the data model based on the primary key given in the GET variable. If the data model is not found, an HTTP exception will be raised.
log()
method
|
public void log(string $message)
| ||
| $message | string | |
Source Code: app/controllers/UserController.php#294 (show)
public function log($message){
}
log message
performAjaxValidation()
method
|
protected void performAjaxValidation(CModel $model)
| ||
| $model | CModel | the model to be validated |
Source Code: app/controllers/UserController.php#282 (show)
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
Performs the AJAX validation.