【发布时间】:2015-01-24 13:50:39
【问题描述】:
我想在成功登录后创建随机会话并在注销后将其销毁。 怎么办?我用 $this->user->setState 我添加了这段代码
class UserIdentity extends CUserIdentity {
protected $_id;
public function authenticate(){
$user = User::model()->find('LOWER(username)=?', array(strtolower($this->username)));
if(($user===null) || ($this->password!==$user->password)) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
$this->_id = $user->id;
$this->username = $user->username;
$this->user->setState('random',Yii::app()->user->random);
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId(){
return $this->_id;
}
}
【问题讨论】:
-
你在哪里给 Yii::app()->user->random 赋值?
-
即使我写 $this->user->setState('random','value');它不起作用
-
使用
$this->setState而不是$this->user->setState -
谢谢!什么是真的? $this->setState 或 Yii::app()->user->
-
Yii::app()->user 是 UserIdentity 的一个实例,你应该在其余代码中使用它。在这里使用 $this 是因为您正在为当前登录的用户设置状态。