1

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

    /**

会有什么问题?我运行了作曲家更新。为什么只缺少安全性?

4

3 回答 3

1

您应该使用 getSecurity()

 Yii::$app->getSecurity()->generatePasswordHash($password);
于 2016-03-08T07:32:51.890 回答
1

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

作曲家全局需要“fxp/composer-asset-plugin:~1.1.1”

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

于 2016-03-08T10:05:20.247 回答
-1

这是正确的:Yii::$app?

不应该是 Yii::app()

我还不熟悉 2.x。

于 2016-03-08T07:34:30.740 回答