PHP Tips & Tricks YII2

How to Get Logged In User Details in Yii2

How to Get Logged In User Details in Yii2 July 27, 2017Leave a comment

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

Yii2.0 Framework

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 🙂

How to Get Logged In User Details in Yii2
5 (100%) 1 vote

(Visited 1 times, 1 visits today)

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

Leave a Reply

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