Answer the question
In order to leave comments, you need to log in
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, 'ошибка');
}
}
...
}
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,
]);
}
...
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question