How to get user role in Yii2?
I searched and read Yii2 guide but I didn't find any solution.
You can get Roles for an user by using getRolesByUser function
You can use it like this
\Yii::$app->authManager->getRolesByUser($user_id);
You can use:
Yii::$app->authManager->getRolesByUser(Yii::$app->user->getId());
I use :
if (\Yii::$app->authManager-> getAssignment($role,$rule_id))
for filtering user id
and role
in rbac, More details on Yii2 Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With