When updating an image using Yii2, I face a validation problem. He always asks me to upload an image. But I do not want this. Always updating the image is not required.
I tried skipOnEmpty , but it does not work properly, it causes an effect when loading a photo, which is also incorrect.
Please, help!
Model
public function rules() { return [ [['carid', 'name'], 'required'], [['carid', 'coverphoto', 'status'], 'integer'], [['name'], 'string', 'max' => 200], [['imageFiles'], 'image','extensions' => 'png, jpg, jpeg, gif', 'maxFiles' => 4, 'minWidth' => 100, 'maxWidth' => 800, 'minHeight' => 100, 'maxHeight'=>600,'skipOnEmpty' => true], ]; }
controller
public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->photoid]); } else { return $this->render('update', [ 'model' => $model, ]); } }
yii2
Sangita pal
source share