Yii2 - 未知属性 - yii \ base \ UnknownPropertyException获取未知属性:yii \ web \ Application :: security

时间:2016-03-08 06:56:48

标签: php yii2 application-security

我安装了yii2并编写了应用程序。我用git。当我将应用程序传输到服务器时。一切都很好看。但是当我尝试登录时,我收到了这条消息:

Unknown Property – yii\base\UnknownPropertyException

获取未知属性:yii \ web \ Application :: security

1. in C:\httpd\omg\omg-new\vendor\yiisoft\yii2\base\Component.php at line 142
133134135136137138139140141142143144145146147148149150151

            foreach ($this->_behaviors as $behavior) {
                if ($behavior->canGetProperty($name)) {
                    return $behavior->$name;
                }
            }
        }
        if (method_exists($this, 'set' . $name)) {
            throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
        } else {
            throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
        }
    }

    /**
     * Sets the value of a component property.
     * This method will check in the following order and act accordingly:
     *
     *  - a property defined by a setter: set the property value
     *  - an event in the format of "on xyz": attach the handler to the event "xyz"

2. in C:\httpd\omg\omg-new\vendor\yiisoft\yii2\di\ServiceLocator.php – yii\base\Component::__get() at line 72
3. in C:\httpd\omg\omg-new\common\models\User.php – yii\di\ServiceLocator::__get() at line 154
148149150151152153154155156157158159160

     *
     * @param string $password password to validate
     * @return boolean if password provided is valid for current user
     */
    public function validatePassword($password)
    {
        return Yii::$app->security->validatePassword($password, $this->password_hash);
    }

    /**
     * Generates password hash from password and sets it to the model
     *
     * @param string $password

4. in C:\httpd\omg\omg-new\common\models\LoginForm.php – common\models\User::validatePassword() at line 45
39404142434445464748495051

     * @param array $params the additional name-value pairs given in the rule
     */
    public function validatePassword($attribute, $params)
    {
        if (!$this->hasErrors()) {
            $user = $this->getUser();
            if (!$user || !$user->validatePassword($this->password)) {
                $this->addError($attribute, 'Incorrect username or password.');
            }
        }
    }

    /**

会出现什么问题?我跑了作曲家更新。为什么只缺少安全性?

3 个答案:

答案 0 :(得分:1)

您应该使用getSecurity()

 Yii::$app->getSecurity()->generatePasswordHash($password);

答案 1 :(得分:1)

好的,我发现了一个错误。 运行composer update时。它更新了作曲家,但在安装手册中找到了你必须执行

composer global require" fxp / composer-asset-plugin:~1.1.1"

这个选项我忘了在新电脑上全新安装了。现在一切正常

答案 2 :(得分:-1)

这是否正确: 警予:: $应用程序?

不应该是Yii :: app()

我还不熟悉2.x。