Tag: YII2

How to get ID of the logged-in User in Yii2?

Logged in user information will be stored in Yii::$app->user->identity variable. The authenticated user identity information can be retrieved via Yii::$app->user->identity.
You can get ID by using below code.

<?= \Yii::$app->user->identity->ID ?>

If you have any doubts, Please comment here.

How to get username of the logged-in User in Yii2?




Logged in user information will be stored in Yii::$app->user->identity variable. The authenticated user identity information can be retrieved via Yii::$app->user->identity.
You can get username by using below code.

<?= \Yii::$app->user->identity->username ?>

If you have any doubts, Please comment here.