【问题标题】:How can use setstate in Yii如何在 Yii 中使用 setstate
【发布时间】: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 是因为您正在为当前登录的用户设置状态。

标签: php yii setstate


【解决方案1】:

使用 $this->setState 代替 $this->user->setState

【讨论】:

    猜你喜欢
    • 2014-10-31
    • 1970-01-01
    • 2019-10-12
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多