Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

yii2

Model's function for which I got this error:

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

public function generateAuthKey()
{
    $this->auth_key = Yii::$app->security->generateRandomString();
}
like image 513
john sunam Avatar asked Jan 08 '23 10:01

john sunam


1 Answers

Add

use Yii;

Before your class declaration.

Or add a backslash in front of the Yii word.

$this->password_hash = \Yii::$app-> ...
like image 175
Jap Mul Avatar answered Jan 16 '23 21:01

Jap Mul