获取yii2中的用户名 [英] Get the name of the user in yii2
本文介绍了获取yii2中的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取yii2中登录用户的名称? 我可以通过
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;
不起作用,并且
Yii::$app->user->name;
也不起作用.
推荐答案
登录时,用户信息将存储在Yii::$app->user->identity
变量中.
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.
这篇关于获取yii2中的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文