Php Yii2-未知财产–;yii\base\UnknownPropertyException获取未知属性:yii\web\Application::security

Php Yii2-未知财产–;yii\base\UnknownPropertyException获取未知属性:yii\web\Application::security,php,yii2,application-security,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 13313413513613

嗨,我安装了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.');
            }
        }
    }

    /**

有什么问题吗?我运行了composer更新。为什么只缺少安全性?

您应该使用getSecurity()

这是否正确: Yii::$app

应该是Yii::app()吗

我还不熟悉2.x。

好的,我发现了一个bug。 运行composer update时。它更新了composer,但在安装手册中发现您必须执行它

composer global需要“fxp/composer资产插件:~1.1.1”


在新计算机上重新安装时,我忘记了此选项。现在一切正常了

您的多行评论前面是否缺少斜杠?您得到的错误消息是什么,我只是看到了代码?代码是否为错误消息?是斜杠缺失这是yii异常,添加了详细的异常描述。确定可以使用getSecutiry进行尝试。忘了提了。在最初的开发服务器上,一切正常。但当我将代码克隆到另一台服务器时,会出现问题。一台服务器是Windows,另一台是unix/linux?好的,尝试getSecurity()相同的问题:调用未知方法:yii\web\Application::getSecurity()这两台都是Windows系统。最终安装将在linux上进行,但现在要解决这个问题,我希望双方使用相同的系统。我想这和作曲家有关吧?
 Yii::$app->getSecurity()->generatePasswordHash($password);