Answer the question
In order to leave comments, you need to log in
How can I add a new value to Yii::$app->user?
Yii2 has a Yii::$app->user class.
Now I can call Yii::$app->user->getId() from anywhere in the application and get the user id.
Can you please tell me how to add more like this:
Yii::$app->user->getRole() - Role
Yii::$app->user->getUsername() - Name
...
???
Answer the question
In order to leave comments, you need to log in
user is a component.
What you are most likely looking for is \Yii::$app->user->identity.
For example, \Yii::$app->user->identity->role.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question