Good afternoon, there is such a code in the controller:
public function actionRegistration() { if(Yii::$app->request->isAjax) { $usersModel = new UsersModel(); $usersModel -> setScenario('registration'); $usersModel -> setAttributes($_POST['UsersModel'], true); if($usersModel -> validate() && $usersModel -> registration()) { $usersModel -> id = $usersModel ->guid(); $usersModel -> login = $usersModel->email; $usersModel -> hash = md5(rand()) . '_' . md5(rand()); $usersModel -> save(false); return json_encode([200, Yii::t('yii', 'In a letter sent to your e-mail to confirm your email address. mail, please read it')]); } else { return json_encode([500, Yii::t('yii', 'incorrectly entered e-mail')]); } } else { throw new HttpException(404, Yii::t('yii', 'Page not found.')); } }
It seems simple, but when you call save()
throws an error:
<pre>Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[HY000]: General error: 1364 Field 'login' doesn't have a default value The SQL being executed was: INSERT INTO `users` (`id`) VALUES (NULL)' in C:\sergey\sites\bitask.com\vendor\yiisoft\yii2\db\Schema.php:534
For some reason, the id field is assigned NULL, in yii 1.1 all the time I just called save (), and then the guys got a bit too smart. When calling var_dump ($ usersModel), it shows that all the fields are correctly filled in, especially id can’t get it, thanks in advance for the help.