model->save() Not Working In Yii2

后端 未结 10 1558
情歌与酒
情歌与酒 2020-12-06 01:10

Previously, I was not using $model->save() function for inserting or updating any data. I was simply using createCommand() to execute query and

10条回答
  •  日久生厌
    2020-12-06 02:09

    in your model i found First name , last name , email , password is required fields and in your controller you are updating or saving only

     $model->auth_key = $auth_key;
            $model->password = $password;
            $model->confirm_password= md5($post["confirm_password"]);  /// add  this line
            $model->registration_ip = $registration_ip;
            $model->created_at = $created_at;
    

    but first name and last name and email id are required so it will throw validation error , to check this error use

    $model->load();
    $model->validate();
    var_dump($model->errors);
    

    it will show you the error . correct that errors then model will get save. you can solve that error using Scenario or

    $model->saveAttributes('favorite_book'=>$model->favorite_book,'favorite_movie'=>$model->favorite_movie);
    

    I hope it will help you.

提交回复
热议问题