How can I get the name of the logged-in-user in yii2? I can get the user-id with
Yii::$app->user->id;
and I know that I could find the name in the database but I want a direct way. The name-column in the database has the name “username”, but
Yii::$app->user->username;
doesn’t work and
Yii::$app->user->name;
doesn’t work either.
Advertisement
Answer
On login the user information will be stored in Yii::$app->user->identity
variable.
For more information have a read through the User Authentication documentation in the official guide.