php - Yii2 : Bad Request (#400) Missing required parameters: id -


my controller :

public function actioncreate()     {             $model = new createbookings();              if ($model->load(yii::$app->request->post()))              {                 $imagename = $model->primary_name;                 $model->file = uploadedfile::getinstance($model, 'file');                 $model->file->saveas('uploads/'.$imagename.'.'.$model->file->extension);                 $model->id_image = 'uploads/'.$imagename.'.'.$model->file->extension;                 $model->save();                  return $this->redirect(['view', 'id' => $model->id]);             } else              {                 return $this->render('create', [                     'model' => $model,                 ]);             }      } 

getting error on submitting form, dont know what's wrong it.. tried $model->save(false); ..but not working well

try getprimarykey() method:

public function actioncreate()     {             $model = new createbookings();              if ($model->load(yii::$app->request->post()))              {                 $imagename = $model->primary_name;                 $model->file = uploadedfile::getinstance($model, 'file');                 $model->file->saveas('uploads/'.$imagename.'.'.$model->file->extension);                 $model->id_image = 'uploads/'.$imagename.'.'.$model->file->extension;                 if($model->save())                 {                     $lastinsertid = $model->getprimarykey();                    return $this->redirect(['view', 'id' => $lastinsertid]);                 }                else                {                    // print_r($model->geterrors()); => check whether validation errors there                }               } else              {                 return $this->render('create', [                     'model' => $model,                 ]);             }      } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -