Hi to all, I have a model for Items. I this model I have a relationship to another model Images where I save the path to the item images in which an item can have as many images.
When an item is deleted I need to delete the path in the image table and this works fine but I need to delete the file(image) of the item too. Here is my code but is not deleting the file which is the image using the unlink function. I might be missing something please help.
protected function afterDelete()
{
parent::afterDelete();
ItemRecommendations::model()->deleteAll('item_id=' .$this->id);
ItemTag::model()->updateFrequency($this->tags, '');
//Delete images location
$image_path = Yii::app()->getBasePath().'/../../uploads/item/';
//query table where id = current id
$item_data = ItemImage::model()->findAll('item_id =' .$this->id);
if(!empty($item_data->image_path))
unlink($image_path.$item_data->image_path);
unlink($image_path.$item_data->image_thumb_path);
//Delete all the image path for the current item
ItemImage::model()->deleteAll('item_id =' .$this->id);
}

Help













