Dear All ,
Could some one check this case ? is it a bug or am I doing something wrong?
Here is the below simple code
class MyWebUser extends CWebUser {
private $_dbUser = false;
public function getDbUser()
{
if($this->_dbUser === false){
$this->_dbUser = $this->isGuest ? null : User::model()->findByPk($this->id);
}
return $this->_dbUser;
}
}
Whenever I call Yii::app()->user->dbUser from different actions
$this->_dbUser === false
is getting satisfied every time and pulling the data from the database . My assumption was It should call the
User::model()->findByPk($this->id)
very first time and for all other times it should be from session . I did put the trace statement inside the if condition and trace is printing for each call . Did some one checked this or noticed?
If I use
Yii::app()->user->setState('dbUser', User::model()->findByPk($this->id));
The value is getting stored in session and I am able to use it for my further actions
I see some thing fishy going on with the first approach , If the above both the approaches are for the same reason do we have any advantage one on another ?
Thanks for your help and checking this
Regards
Yii Fan