> I'm new to cake so I may not be 100% right, but why not you create a
> beforeDelete() method in your Photo model? Use this delete the
> associated image file.

This looked promising until i realized that I need the $id to get the
file path of the photo and delete it. I would need to put something
like this in my Model:

function beforeDelete($id) {
        $photo = $this->Photo->findById($id);
        $file_path = substr($photo['Photo']['file_path'], 1); // remove the
leading slash for cake
        // Code from Chris Partridge:
        if($file = new File($file_path)) {
                if(!$file->delete()) {
                        trigger_error('delete error');
                        return false;
                }
        } else {
                return false;
        }
        return true;
}

Unfortunately, looking at the API the beforeDelete method takes no
arguments when its called by del:

http://api.cakephp.org/model__php4_8php-source.html#l00956

So how would my beforeDelete method know what to do?

Is this a dead end or am I wrong?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to