I'm trying to delete images when deleting the container of those images with a cascading model::delete
The cascading works fine, but I can't get the model call back afterDelete to work properly so I can delete the actual image files when doing the delete.
function beforeDelete() {
$containerId = $this->id;
$numberOfImages = $this->RelatedImage->find('count', array('conditions' => array('RelatedImage.container_id' => 'containerId')));
if ($numberOfImages > 0){
$relatedImages = $this->RelatedImage->find('all', array('conditions' => array('RelatedImage.container_id' => 'containerId')));
foreach ($relatedImages as $image) {
$myFile = WWW_ROOT . 'image' . $containerId . '_i' . $image['RelatedImage']['id'] . '.jpg';
unlink($myFile);
$myThumb = WWW_ROOT . 'img/' . $image['RelatedImage']['thumbnail'];
unlink($myThumb);
}
return true;
} else{
return false;
}
}
The if statement fails each time, even though I know there are images in the table. If I can get the if statement to at least execute i will add further validation on the unlink.