Hi guys
How to create access role in yii and where in yii application part ?
I want to create access role in yii application but i have a problem and dont know about where to assign role in yii like
i have three department role
1.admin -: admin have a all access role in our application
2.staff -: staff same of page and access role like to edit or update
3.user -: user have a all access page only viewing in our application
These type of role can set in controller but i can justify where to write all access in yii and how to set access role ,
thank
hari maliya
I sold there question answer but i use another type method like this:
Step 1: Write a same code in UserIdentity.php file
public function authenticate()
{
$user = User::model()->findByAttributes(array('email'=>$this->username));
if ($user===null) { // No user found!
$this->errorCode=self::ERROR_USERNAME_INVALID;
} else if ($user->password !== ($this->password) ) { // Invalid password!
$this->errorCode=self::ERROR_PASSWORD_INVALID;
} else { // Okay!
$this->errorCode=self::ERROR_NONE;
// Store the role in a session and assign action for role
$this->setState('role', $user->role);
$this->_id = $user->id;
}
return !$this->errorCode;
}
setp 2: Then After write same code in YourController.php, you to access and assign role in your staff, admin, user.
public function accessRules()
{
if( Yii::app()->user->getState('role') =="admin")
{
$arr =array('index','calendar','contact','staff','service'); // give all access to admin
}else if( Yii::app()->user->getState('role') =="staff")
{
$arr =array('index','staff','staffcalendar','update'); // give all access to staff
}
else
{
$arr = array(''); // no access to other user
}
return array(
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>$arr,
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
Step 3: Now you can access role based user and perform action.