如何在Yii中使用setstate

时间:2015-01-24 13:50:40

标签: php yii setstate

我希望在成功登录后创建随机会话,并在注销后将其销毁。 怎么办?我使用了$ 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;
    }
}

1 个答案:

答案 0 :(得分:0)

使用$ this-> setState而不是$ this-> user-> setState