Home >Backend Development >PHP Tutorial >yii2自带的User.php类(在common/model/User.php)找不到login()方法

yii2自带的User.php类(在common/model/User.php)找不到login()方法

WBOY
WBOYOriginal
2016-06-06 20:38:031028browse

现在的问题是这样的:yii2自带的User.php类(在common/model/User.php)找不到login()方法

顺便问一下,yii2自带的验证密码的,加密方式是什么?可以做修改吗?

回复内容:

现在的问题是这样的:yii2自带的User.php类(在common/model/User.php)找不到login()方法

顺便问一下,yii2自带的验证密码的,加密方式是什么?可以做修改吗?

...那个login本来就不在common\model\User.php里,另外Yii::$app->user里的这个user也不是common\model\User.php,而是yii\web\User,那么login也就找到了;

<code>public function login(IdentityInterface $identity, $duration = 0)
    {
        if ($this->beforeLogin($identity, false, $duration)) {
            $this->switchIdentity($identity, $duration);
            $id = $identity->getId();
            $ip = Yii::$app->getRequest()->getUserIP();
            if ($this->enableSession) {
                $log = "User '$id' logged in from $ip with duration $duration.";
            } else {
                $log = "User '$id' logged in from $ip. Session not enabled.";
            }
            Yii::info($log, __METHOD__);
            $this->afterLogin($identity, false, $duration);
        }

        return !$this->getIsGuest();
    }
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn