N
N
nepster-web2014-03-20 23:02:32
Yii
nepster-web, 2014-03-20 23:02:32

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

1 answer(s)
Y
Yuri Morozov, 2014-03-20
@nepster-web

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 question

Ask a Question

731 491 924 answers to any question