简体   繁体   中英

Joomla 3 deleteList remove Images

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?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM