Search code examples
phppermissionsyii2access-control

Yii2 - Get access permissions for another users


In Yii2 we can check access of current user for any permissions by yii\web\User::can() as follow:

if (\Yii::$app->user->can('createPost')) {  // user_id=1
    // create post
}

How can we check access for another users such as user_id = 5 in yii2?


Solution

  • Like this:

    if (\Yii::$app->authManager->checkAccess($user_id, 'createPost')) {}