Answer the question
In order to leave comments, you need to log in
Yii2 how to accept files from users?
After accepting the files, an error pops up "You must enter a required id parameter" I read the code, everything seems to be correct, tell me where the error is ..
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->image = UploadedFile::getInstance($model, 'image') ;
if( $model->image ){
$model->upload();
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
public function upload(){
if($this->validate()){
$path = 'upload/store/' . $this->image->baseName . '.' . $this->image->extension;
$this->image->saveAs($path);
return true;
}else{
return false;
}
}
<?= $form->field($model, 'image')->fileInput() ?>
Answer the question
In order to leave comments, you need to log in
actionUpdate($id){}
requires an id parameter, which is most likely not passed to the server
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question