1

I am currently overriding Joomla 3's deleteList like so:

public function delete(){
    if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
    $path = JPATH_ROOT;
    $path = JPath::clean($path. DS ."images". DS ."menu_slider". DS );

    foreach(glob($path.'*/penguins.*') as $image){
        unlink($image);
    }
    return parent::delete();
}

In the item or items there's a image associated with them, so the database has the following:

id title image

So my question really is how would i get the image name assigned to the item or items when deleting?

1 Answers1

1

Probably you're aware that controller triggers model method delete, then it load JTable which deletes the entry. My suggestion would be to extend JTable class with following method in /administrator/components/com_YourExtension/tables/YourTableFile.php :

public function delete($pk = null)
{
    jimport( 'joomla.filesystem.file' );
    $path = JPath::clean(JPATH_ROOT . "/images/menu_slider/");
    if (JFile::exists($path . $this->image)
        JFile::delete($path . $this->image);

    return parent::delete($pk);
}
di3sel
  • 2,002
  • 15
  • 24
  • Nope, I didnt.. Im still rather new to all this. Thank you. But I keep getting an error from joomla Failed deleting lighthouse.jpg, Also I removed my original delete override, was i correct in doing so? –  Oct 15 '13 at 08:40
  • If you keep getting the error please try to replace JFile::delete($path . $this->image); with unlink($path . $this->image); Also you need to remove delete method from your controller and let it do his native behavior. – di3sel Oct 15 '13 at 08:42
  • Well this one needs debugging then... Can you try to insert the following code before 'if (JFile::exists($path . $this->image)' line: echo $path . $this->image; die(); And check if filepath is right. – di3sel Oct 15 '13 at 08:46
  • Sorry, Im being stupid again, the problem is the image gets re-sized when uploaded and then moved into different folders, that's why I originally used $path.'*/penguins.*' so that all the sub folders are selected. –  Oct 15 '13 at 08:55
  • Can you copy and example structure how single entry images are stored (with paths and filenames)? For example entry Penguin has image, can you tell me all folders and filenames that image is located in? – di3sel Oct 15 '13 at 08:56
  • I fixed it! JFile::delete(glob($path . '*/' . $this->image)); –  Oct 15 '13 at 08:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39251/discussion-between-dawid-van-der-hoven-and-di3sel) –  Oct 15 '13 at 09:00