I am building a site that is using CWebUser and CDbHttpSession. This site needs to use user state named group for authentication. But, I face problem that when I use CDbHttpSession, the CWebUser cannot get group state:
Property "CWebUser.group" is not defined.
Although that, when I use CHttpSession (default), It has no problem. When I open CWebUser.php file, I see that this file has some code as follow:
...
public function getState($key,$defaultValue=null)
{
$key=$this->getStateKeyPrefix().$key;
return isset($_SESSION[$key]) ? $_SESSION[$key] : $defaultValue;
}
...
public function setState($key,$value,$defaultValue=null)
{
$key=$this->getStateKeyPrefix().$key;
if($value===$defaultValue)
unset($_SESSION[$key]);
else
[b]$_SESSION[/b][$key]=$value;
}
...
public function hasState($key)
{
$key=$this->getStateKeyPrefix().$key;
return isset($_SESSION[$key]);
}
...
public function clearStates()
{
$keys=array_keys($_SESSION);
$prefix=$this->getStateKeyPrefix();
$n=strlen($prefix);
foreach($keys as $key)
{
if(!strncmp($key,$prefix,$n))
unset($_SESSION[$key]);
}
}
...
This code use $_SESSION variable instead of Yii::app()->session. So is this a reason?
I am having the same problem as described above. The problem arises when the user logs in. Then after some time of inactivity the user refreshes the screen and then the message [font="Century Gothic"]Property "CWebUser.userclass" is not defined[/font] pops up. Userclass is the state I defined in the UserIdentity class.
Is there a solution for this problem yet?
Kind regards!
(ps. Its my first post until now and I have been using Yii for some months already. Yii is great and very well documented!)
I think the problem of geertp is that geertp did not set config values and validate correctly.
First, I think this has small value of session time life.
Second, when geertp call "CWebUser.userclass", he/she did not check to sure that user is login or not. Because the states of CWebUser only exist when user loged in successful.
About my problem, I have fix it. This error only occurs when I set the string in unicode charset to state. So, I have remove them from states list.
At index.php I can access $_SESSION variable but in function init() of controller I can not access $_SESSION - value of $_SESSION was changed. I try with CHttpSession but it same.
But at login I used CUserIdentity to save username and id. it OK