Yii2.0 Framework

How to Get Logged In User Details in Yii2

In this tutorial, you will go through how to get logged in user details in Yii2. 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 variable.

If you want to get logged in user details, then you can try below code:

To Get Logged In User Data:

$user = \Yii::$app->user->identity;
print_r($user);//Print all user info data

To Get Logged In User ID:

$userId = \Yii::$app->user->identity->id;

To Get Logged In Username:

$username = \Yii::$app->user->identity->username;

Hope this is useful for you 🙂

(Visited 2 times, 1 visits today)
Chandra Kumar

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

0 Comment

Leave a Comment

Your email address will not be published. Required fields are marked *