Hi Joshua, 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.
Steven On Mar 17, 4:06 am, "Joshua McFarren" <[EMAIL PROTECTED]> wrote: > Let me preface this by saying that I'm pretty new to cakePHP and PHP > for that matter. My background is in PERL and cakePHP lewered me over-- > but thats neither here nor there. > > I'm writing an application for a real estate broker that primarily > stores and retreives information about houses for sale which are > refered to as Listings. Obviously I have a Listing Class. I also have > a Photo Class. Photos belongTo Listings and Listings haveMany Photos > which are dependent. Therefore when a Listing is deleted it's > associated rows in the photos table are also deleted. This is intended > and expected behavoir. > > Here's the rub: > Photos are stored on the server as files and information about them is > stored in the photos table. Therefore my delete method in the > PhotoController needs to get the file path of the photo from the table > before the row is destroyed so that it can remove the file from the > server. This works fine. The catch is that I needed to write similar > code into the delete method of my ListingsController and this seems > redundant. > > I have a little expereince with Objective-C and since it currently > doesnt have garbage collection its important to alloc and free all > your declared memory space. The most common way to do this is to > override the new and free methods with specific versions in your Class > take care of cleanup and then call the parent Class' method to take > care the object business. > > To me it seems that there should (or maybe is) a way to do this in > cake. That way I could override the del method in my Photo Class so > that it deletes the files from the server and then calls the Parent > Class' method to remove the rows from the photos table. In this way > when a Listing is deleted, it automatically calls the overridden del > Method for the Photo Class, because of dependence, the photos are > deleted automatically without the need to put this in the delete > Method of the ListingsController. > > Hope this makes some sense. Or maybe I'm just crazy. > > Best, > Joshua --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
