Hi guys, this is my actionUpdate controller
if(isset($_POST['Products']))
{
$model->attributes=$_POST['Products'];
$model->image=CUploadedFile::getInstance($model, 'image');
// this line checks if theres is an file, if it does, it can be leave blank, else upload new
if ( ( is_object($model->image) && get_class( $model->image ) === 'CUploadedFile' ))
if($model->save()) {
if( strlen($model->image) > 0 )
$model->image->saveAs(Yii::app()->basePath.'/../uploads/'.$model->image);
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('update',array(
'model'=>$model,
));
how do i add a ‘single’ button to delete the file and remove the data for the image field in actionUpdate?? as well as when deleting the row in actionDelete
It should unlink this file
unlink(Yii::app()->basePath.’/../uploads/’.$model->image);
thanks
========= edit ===================
i solved the actionDelete with the help of this post : http://www.yiiframework.com/forum/index.php/topic/30689-any-onbeforedelete-example/
by using afterDelete().
but how to do it in the update?
I need an delete Image button in the update,
and i have this function in the model
public function deleteImage()
{
unlink(Yii::app()->basePath.'/../uploads/'.$this->image);
}
how do i call this function in the update crud by pressing the button?