Yii::$app->user->identity->username获取数据,显示为空,var_dump(ii::$app->user->identity)
common\models\register\LoginUser Object
(
[username] =>
[password] =>
[rememberMe] => 1
[_user:common\models\register\LoginUser:private] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[username] => xiaoqiang
[password] =>
[phone] => 18094570201
[ip] =>
[status] => 10
[password_hash] => $2y$13$MPXhbqGADeuHLI6L.ld0vOy6KNoP0MDMty/8qUZf5kY.oh0X0Rqk2
[auth_key] =>
[created] => 0000-00-00 00:00:00
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[username] => xiaoqiang
[password] =>
[phone] => 18094570201
[ip] =>
[status] => 10
[password_hash] => $2y$13$MPXhbqGADeuHLI6L.ld0vOy6KNoP0MDMty/8qUZf5kY.oh0X0Rqk2
[auth_key] =>
[created] => 0000-00-00 00:00:00
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
吧你这个类common\models\register\LoginUser里面定义的$username,这个属性去掉,自定义的属性和数据库里面的字段重复了
你确定你处于登录状态?