简体   繁体   中英

YII: How authenticated user details are stored in session

I am new to this framework.

I need to implement authentication using google.

So I wanted to know how this framework stores the authenticated user details in session.

I printed the session but I saw some different session variable name.

I want to know how it is created.

Following is the session array:

[e7ebc265ca1cd5fe8c265ca60cecda89__id] => 3
[e7ebc265ca1cd5fe8c265ca60cecda89__name] => david
[e7ebc265ca1cd5fe8c265ca60cecda89__states] => Array
    (
    )

You can used setState and getState for accessing session value in yii.

setState:

 Yii::app()->user->setState('userId', $user->id);
 Yii::app()->user->setState('username', $user->username);
 Yii::app()->user->setState('userEmailAddress', $user->email_address);
 Yii::app()->user->setState('userFullName', $user->first_name . ' ' . $user->last_name);
 Yii::app()->user->setState('gender', $user->gender);

getState:

Yii::app()->user->getState('userId');
Yii::app()->user->getState('username');
Yii::app()->user->getState('userEmailAddress');
Yii::app()->user->getState('userFullName');
Yii::app()->user->getState('gender');

OR You can access session data.

Yii::app()->user->userId;
Yii::app()->user->username;
Yii::app()->user->userEmailAddress;
Yii::app()->user->userFullName;
Yii::app()->user->gender;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM