I’m trying to show the username when i’m logged but doesn’t work.
views/layouts/main.php
'<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link']
)
. Html::endForm()
. '</li>'
If i check the content of Yii::$app->user->identity i have:
object(app\models\User)#85 (13) { ["id"]=> NULL ["username"]=> NULL ["password"]=> NULL ["authKey"]=> NULL ["accessToken"]=> NULL ["_attributes":"yii\db\BaseActiveRecord":private]=> array(9) { ["id"]=> int(1) ["username"]=> string(5) "admin" ["auth_key"]=> string(32) "1..." ["password_hash"]=> string(60) "$2y$13..." ["password_reset_token"]=> NULL ["email"]=> string(27) "mail@mail.com" ["status"]=> int(10) ["created_at"]=> int(1458584296) ["updated_at"]=> int(1458584296) } ["_oldAttributes":"...
The first "username" is NULL, if i check Yii::$app->user->identity->attributes:
array(9) { ["id"]=> NULL ["username"]=> NULL ["auth_key"]=> string(32) "1..." ["password_hash"]=> string(60) "$2y$13..." ["password_reset_token"]=> NULL ["email"]=> string(27) "mail@mail.com" ["status"]=> int(10) ["created_at"]=> int(1458584296) ["updated_at"]=> int(1458584296) }
Why doesn’t work like the yii2 app advanced? Thank you.