A
A
Alexander Ivanov2017-03-28 18:55:37
Yii
Alexander Ivanov, 2017-03-28 18:55:37

How to fix Class 'app\models\User' not found error in Yii2?

Remember YII2
Model

namespace app\models;

use Yii;
use yii\base\Model;
//use yii\db\ActiveRecord;

class LoginForm extends Model
{
...
    public function validatePassword($attribute,$params){
        $user = User::findOne([
          'email'=>$this->email
        ]);

        if(!$user || ($user->password != $this->password)){
            $this->addError($attribute, 'ошибка');
        }
    }
...
}

controller
namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\RegistrationForm;

class BaseController  extends Controller{
...
 public function actionLogin()
  {
    if (!Yii::$app->user->isGuest) {
      return $this->goHome();
    }

    $login = new LoginForm();
    if ( Yii::$app->request->post('LoginForm')) { //$login->load(Yii::$app->request->post('LoginForm') && $login->login()
      $login->attributes = Yii::$app->request->post('LoginForm');
      if($login->validate()){
        var_dump("Всё тип топ");
        die();
      }
      //return $this->goBack();
    }

    return $this->render('login', [
      'model' => $login,
    ]);
  }
...
  }

I google but have not yet understood something
error ->
$user = User::findOne

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex stephen, 2017-03-28
@cimonlebedev

Does the User model really exist?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question