T
T
T3R3AND2020-08-30 00:35:19
Yii
T3R3AND, 2020-08-30 00:35:19

Yii2 passing empty login?

Hello! I did registration and authorization according to the lesson, but in the end for some reason the username does not pass to me

SiteController

public function actionSignup(){
 if (!Yii::$app->user->isGuest) {
 return $this->goHome();
 }
 $model = new SignupForm();
 if($model->load(\Yii::$app->request->post()) && $model->validate()){
 $user = new User();
 $user->username = $model->username;
 $user->password = \Yii::$app->security->generatePasswordHash($model->password);
 if($user->save()){
 return $this->goHome();
 }
 }

 return $this->render('signup', compact('model'));
}



dumped the username dump everything! and the error is (prnt.sc/u86hfb)
mistake

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'username'
The SQL being executed was: INSERT INTO `user` (`id`) VALUES (DEFAULT)
Error Info: Array
(
    [0] => 23000
    [1] => 1062
    [2] => Duplicate entry '' for key 'username'
)
↵
Caused by: PDOException
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'username'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question