php - How I can delete image from DB in Yii? -


how can delete image view

<?php if(!empty($model->image_name) > 0) { ?>         <div class="row">                     <?php echo chtml::image(img::getpostthumb($model->image_name, 700, 1000));?>                     <b><?php echo chtml::link('delete', array('mobilelandingpost/deleteimage','imagename'=>$model->image_name,'id'=>$model->id),array('confirm' => 'سنقوم بحذف الصور موافق ؟'));?></b>         </div> <?php } ?> 

and controller

public function actiondeleteimage($imagename,$id){           $model= mobilelandingpost::model()->find(array(                                          'condition'=>'image_name=:image_name ',                                          'params'=>array(':temp_posts_id'=>$imagename))                                     );                 if(!$model)         {                         throw new chttpexception(404,'الصورة التي تريد حذفها غير موجودة');         }          if($model->delete())         {                         yii::app()->user->setflash('success','تم حذف الصورة');                     $this->redirect( array('mobilelandingpost/update','id'=>$id));          }    } 

when press delete model delete need delete image

just delete field & save model.

$model->image_name = ''; $model->save(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -