脚本宝典收集整理的这篇文章主要介绍了在Yii2中更新图像,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过skIPOnEmpty,但它不能正常工作,它会在上传照片时产生效果,这也是不正确的.
请帮忙!!
模型
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],]; }
调节器
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,]); } }
像,
在模型的规则中添加条件以应用场景.
[['imageFiles'],'skipOnEmpty' => true,'on' => 'update-photo-upload'],
并在控制器的操作中使用该场景.
public function actionUpdate($id) { $model = $this->findModel($id); $model->scenario = 'update-photo-upload'; ........ ..... }
以上是脚本宝典为你收集整理的在Yii2中更新图像全部内容,希望文章能够帮你解决在Yii2中更新图像所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。