PHP Web Development Yii YII2

How to Get Logged In User Details in Yii2

How to Get Logged In User Details in Yii2 June 9, 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, 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:

<?php 
//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
\Yii::$app->user->identity->username;
?>

References:

http://www.yiiframework.com/doc-2.0/yii-web-user.html
http://www.yiiframework.com/doc-2.0/guide-index.html#getting-data-from-users


(Visited 52 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 *