Why am I getting the error "Class" app \ models \ Yii "not found"?

The model function for which I received this error:

public function setPassword($password)
{
    $this->password_hash = Yii::$app->security->generatePasswordHash($password);
}

public function generateAuthKey()
{
    $this->auth_key = Yii::$app->security->generateRandomString();
}
+4
source share
2 answers

Add

use Yii;

Before class declaration.

Or add a backslash before the word Yii.

$this->password_hash = \Yii::$app-> ...
+8
source
vhgfb'fghfgh'fghfgh'hhgfhfghfghgfhgfh'e
0
source

Source: https://habr.com/ru/post/1610349/


All Articles