Код: Выделить всё
namespace common\components;
use Yii;
class PhpManager extends \yii\rbac\PhpManager
{
public function getAssignments($userId)
{
if(!Yii::$app->user->isGuest){
$assignment = new \yii\rbac\Assignment;
$assignment->userId = $userId;
$assignment->roleName = Yii::$app->user->identity->role;
return [$assignment->roleName => $assignment];
}
}
...
}
Код: Выделить всё
use yii\rbac\Item;
return [
'items' => [
'updateOwnProfile' => [
'type' => Item::TYPE_PERMISSION,
'description' => 'Редактирование собственного профиля',
'bizRule' => function(){ exit; },
'data' => NULL
],
'guest' => [
'type' => Item::TYPE_ROLE,
'description' => 'Guest',
'bizRule' => NULL,
'data' => NULL
],
'user' => [
'type' => Item::TYPE_ROLE,
'description' => 'User',
'children' => [
'guest',
'updateOwnProfile',
],
'bizRule' => 'return !Yii::$app->user->isGuest;',
'data' => NULL
],
],
];
Код: Выделить всё
if(Yii::$app->user->can('updateOwnProfile')) {
echo 1;
} else {
echo 2;
}
return '';