Updating Image in Yii2 -


while updating image using yii2 i'm facing problem validation.its asking me upload image. don't want this. updating image not necessary.

i tried skiponempty not working cause effect while uploading photo, 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,             ]);         }     } 

you should use scenario update.

like as, add on condition in model's rule applying scenario .

 [['imagefiles'], 'image','extensions' => 'png, jpg, jpeg, gif', 'maxfiles' => 4, 'minwidth' => 100, 'maxwidth' => 800, 'minheight' => 100, 'maxheight'=>600,'skiponempty' => true, 'on' => 'update-photo-upload'], 

and use scenario in controller's action.

public function actionupdate($id) {     $model = $this->findmodel($id);     $model->scenario = 'update-photo-upload';     ........     ..... } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -