1

HI i installed yii2 and write application. I used git. When I transfer application to the server. Everything looks fine. But when I try to login I get this message:

Unknown Property – yii\base\UnknownPropertyException

Getting unknown property: 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.');
            }
        }
    }

    /**

What would be the problem? I ran composer update. Why only security is missing?

MrGapo
  • 348
  • 3
  • 10
  • Is there are slash missing in front of your multi line comment? What is the error message you get, I'm just seeing code? Is the code the error message? – Gerold Meisinger Mar 08 '16 at 07:23
  • Yes slash missing this is yii exception, added detailed exception description. – MrGapo Mar 08 '16 at 07:28

3 Answers3

1

You should use getSecurity()

 Yii::$app->getSecurity()->generatePasswordHash($password);
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Ok Can try with getSecutiry. Forgot to mention. On original development server everything is working fine. But when I git clone code to the other server problem appear. – MrGapo Mar 08 '16 at 07:47
  • One Server is window and the other are unix/linux? – ScaisEdge Mar 08 '16 at 07:49
  • Ok try getSecurity() Same problem: Calling unknown method: yii\web\Application::getSecurity() Both are Windows system. Final install will be on linux, but now to resolve the problem I want same system on both sides. I guess there is something about composer? – MrGapo Mar 08 '16 at 07:54
1

OK I found a bug. When running composer update. It update composer but found in installation manual that you have to execute

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

This option I forget on fresh installation in new computer. Now everything works

MrGapo
  • 348
  • 3
  • 10
-1

Is this correct: Yii::$app?

Shouldn't it be Yii::app()

I'm not familiar with 2.x yet.

Mass
  • 1
  • 1