Zand Php Cake Php

Posted by : bberg
delete post AND unlink image
hi

i have a "posts" table with an image field.

it stores just the filename as a varchar of course.

how can i adapt the "delete" action so it also unlinks the image?

thanks
 
 
Posted by : JamesF
Re : delete post AND unlink image
well you won't be adapting $this->Model->del() i hope but what you

could do is this:



..in your controller action:



//if record was deleted succesfully

if($this->Model->delete($this-
>Model->id))

{

        //if image unlinks succesfully

       if(unlink($image))

       {

                //success

       }



       else

       {

               //image failed to unlink

       }

}

//else record did not delete

else

{

          //record failed to delete

}



i personally would stuff this logic into my model and call it like

this:

$this->Model->myDeleteFunction($data)



you would have to change every reference to $this->Model->function()

to $this->function()

when using the code in the model.
 
 
If you have the better reply, then send it to us. We will display your reply after the approval.
Name : 
Email Id :   
Reply :