Yii2.0 Framework

How to Get Logged In User Details in Yii2

In this tutorial, we will show how you can get the logged in user details in Yii2. After the successful login the user information will be stored in Yii::$app->user->identity variable.

The authenticated user identity information can be retrieved via Yii::$app->user->identity.

Get Logged In User Details:

The below php script will return the logged in user details:

//To get whole logged user data
$user = \Yii::$app->user->identity;
//To get id of logged user
$userId = \Yii::$app->user->identity->id;
//To get username of the logged in user




No Responses

Write a response