Here is the problem I just had. I was trying to delete an image off the disk after all references to it in the database had gone - kinda like unlink(). I couldn’t work out how to access the data in the model. I need to know the filename, so I can delete it. It seems that the only way to do it is:
-
Define a var to hold the filename
private $_tmpImageName;
-
Populate this in the beforeDelete() callback
function beforeDelete() { $this->_tmpImageName = $this->read(null, $this->id); return true; }
-
Then access it in the afterDelete() callback, with something like this:
function afterDelete() { unlink($this->_tmpImageName['Image']['name']); return true; }
If you know of a better way, let me know.
$this->_tmpImageName['Image']['name'] should contain the absolute path to be unlink-ed.
Problably you have just the name of image.
Comment by Gabriel — October 20, 2008 @ 2:29 pm
Turn it in, it’s an example. How do you know that field in my application doesn’t contain the absolute path?
Comment by andyg — October 20, 2008 @ 3:42 pm