[Yii Framework] how to add additional data to the user session
2012-09-07 14:01
661 查看
From the code generated by the yiic, as we know, using these code can only get id and username from Yii::app()->user after logined:
$identity = new UserIdentity($_POST['LoginForm']['username'], $_POST['LoginForm']['password']);
Yii::app()->user->login($identity);
but how about adding some additional data to the user session? Here is the example.
1. implement the method "getPersistentStates()" in UserIdentify, for example:
/*
*
*/
public function getPersistentStates()
{
return array(
'roleId' => $this->_user->role_id,
);
}then, you can get the data via Yii::app()->user->roleId after logined.
2. add the data wherever you want, just use these code:
Yii::app()->user->setState('mykey', 'myvalue');then, you can get the data via Yii::app()->user->mykey.
Have fun with Yii!
$identity = new UserIdentity($_POST['LoginForm']['username'], $_POST['LoginForm']['password']);
Yii::app()->user->login($identity);
but how about adding some additional data to the user session? Here is the example.
1. implement the method "getPersistentStates()" in UserIdentify, for example:
/*
*
*/
public function getPersistentStates()
{
return array(
'roleId' => $this->_user->role_id,
);
}then, you can get the data via Yii::app()->user->roleId after logined.
2. add the data wherever you want, just use these code:
Yii::app()->user->setState('mykey', 'myvalue');then, you can get the data via Yii::app()->user->mykey.
Have fun with Yii!
相关文章推荐
- How to add a user to the sudoers list
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- How to add a user and set environments for the user?
- How to add a user to the sudoers list
- How to add a user and set environments for the us
- codelgniter Failed to write session data (user). Please verify that the ...
- how to close the old Session - if the same username starts a new Session?
- How to add a user to the sudoers list
- How to customise the TWebBrowser user interface (part 1 of 6)
- How to user SSE2 instructions to improve the performance of memory copy?
- How to add the cracked dlls in GAC---let me tell u
- How to find the relation between role and user, t-code, profile
- How to test for a valid user session in a JSP
- 创建虚拟机错误解决:Unable to find a 'userdata.img' file for ABI x86 to copy into the AVD folder.
- [WPF] How to bind to data when the DataContext is not inherited
- How to avoid adding repeat submit the same data if you click the 'Refresh' button of Browser?
- facebook permissions : How to check if the user has already allowed publish_stream for your app
- Delphi如何自定义IE接口(How to customise the TWebBrowser user interface)
- how to set a user-defined process as the system key process
- EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has cl