I want to delete a file after a record in database has been deleted.
Because I use some data from a related model to build a path to image I need to fetch this data in the beforeDelete().
function beforeDelete() {
$info = $this->find('first', array(
'conditions' => array('Media.id' => $this->id),
));
}
function afterDelete() {
unlink(WWW_ROOT . 'img/photos/' . $info['News']['related_id'] . "/" . $info['Media']['file']);
}
How to properly access $info array in afterDelete()?
You can simply declare this var outside method scope.