hi,
I’ve extended CWebUser in order to add ‘my’ user model to it, for accessing misc data in it that I need while rendering pages. I’ve consulted the following Wiki pages and my previous post on this issue is also given below:
http://www.yiiframework.com/wiki/6/
http://www.yiiframework.com/wiki/60/
my previous post: http://www.yiiframework.com/forum/index.php?/topic/20414-solved-design-for-login-and-persistent-user-information/
The relevant section of my custom CWebUser is:
class MyWebUser extends CWebUser {
private $_model;
public $firstName;
public $lastName;
//...
public function login(IUserIdentity $identity, $duration=0) {
parent::login($identity, $duration);
// $identity->getUserModel() is my custom method that returns 'our' user object.
$this->_model = $identity->getUserModel();
$this->firstName = $this->_model->FirstName;
// ...
}
Now for some reason Yii:app()->user->firstName isn’t stored across requests. I’m trying to pull it out in my main.php (layout file), just for debugging:
$u = Yii::app()->user;
echo $u->firstName;
Isn’t the Yii user object supposed to be fully persistent across requests? (I didn’t find approval or negation of this assumption in the class ref). I guess not…
Also, I tried to use CWebUser::setState() to store the same data accompanied by commenting out the properties (public $firstName) and doing:
$this->setState('firstName', $this->_model->FirstName);
but that didn’t help as well.
Is there a way for me to store custom properties in Yii:app()->user so they are easily accessible via:
Yii:app()->user->someCustomProp
?
If its not possible, what would be the most clean and convenient methodology to achieve the same?
TIA,
Boaz.