But im failing to get the user permissions is what i’m thinking, my question is how can i get the current user permissions? I have already checked that my users have their respective roles and permissions assigned.
Usually you don’t need to do this kind of thing. “Yii::$app->user->can()” is just enough.
Check to see whether the user has those permissions that you believe to have assigned.
function conseguirPermisos($nombreP){
$permisos = Yii::$app->authManager->getPermissionsByUser(Yii::$app->user->id);
yii\helpers\VarDumper::dump($perisos);
if (in_array($nombreP, array_keys($permisos))) {
return true;
} else {
return false;
}
}
Note that getPermissionsByUser() doesn’t return an array of strings (an array of permission names), but an array of Permission objects indexed by permission names.