Signup.php model code

public function rules() { return[ [['email', 'password'], 'required'], ['email', 'email'], ['email', 'unique', 'targetClass' => 'app\Models\User'], ['password', 'string', 'min' => 2, 'max' => 10] ]; } public function signup() { $user = new User(); $user->email = $this->email; $user->password = $this->password; return $user->save(); } 

}

Controller code

  if (isset($_POST['Signup'])) { $model->attributes = Yii::$app->request->post('Signup'); if ($model->validate() && $model->signup()) { return $this->goHome(); } } return $this->render('signup', ['model'=>$model]); } 

And view

$ form = ActiveForm :: begin (['class' => 'form-horizontal']);

$ form-> field ($ model, 'email') -> textInput (['autofocus' => true]);

$ form-> field ($ model, 'password') -> passwordInput ();

Register

ActiveForm :: end ();

But the error itself:

enter image description here

  • one
    Well, there is no such model along this path. maybe models need a small letter? or not written at all use app\models\User; above - Alexey Shimansky
  • Nowhere is it written in the app \ Models code, only with a small one - Fitstd
  • one
    and use is in the class of Signup ? - Alexey Shimansky
  • Yes, you were right, not attentive. here is the error ['email', 'unique', 'targetClass' => 'app \ models \ User'], - Fitstd

1 answer 1

Wrong to use app \ models \ User; It was written models with large