Roles Managemant

Hello

I want user access based on their roles. i go through various tutorial on accessRules.

Code is given below

userIdentity.php




$this->setState('role', $role);

$this->setState('admin_user_id', $user->user_id);

$this->setState('admin_username', $user->username);



userController.php




 array('allow', // allow admin user to perform 'admin' and 'delete' actions

                'actions' => array('admin', 'delete', 'create', 'update', 'active', 'inactive'),

                'roles' => array('admin'),



but code is not working. I am confuse how roles are assign in accessRules?

Hi,

You can change as follows in your controller itself…




array('allow', // allow authenticated user to perform 'create' and 'update' actions

            	'actions' => array('create', 'update', 'GenerateExcel', 'GeneratePdf', 'GenerateExcelCustom', 'GenerateMultiplePdf', 'export', 'popgeneral', 'uvview', 'delete', 'view', 'picdelete', 'csv', 'irisdelete', 'DeleteUV'),

            	//'users' => array('@'),   	// Comment this line

            	'expression' => '(Yii::app()->user->role== "admin" || Yii::app()->user->role == "Trial Leader" )', // Here give your session conditions like you can add more arrays expressions... 

        	),



Hope this may helped you!

Cheers!