安装模块后如何在媒体管理器中创建文件夹

How to create a folder in the media manager upon installing a module

嘿,我正在用 Joomla! 制作我的第一个模块。

我想在有人安装我的模块时在 Joomla! 的媒体管理器中创建一个新文件夹。我一直在鸭鸭四处走动,找到了一些信息。但我就是无法让它工作。可能是因为该信息可能适用于较旧的 Joomla!版本。或者我可能执行错了。

总之我想到了以下几点:

mod_mymodule.xml

<extension type="module" version="3.8.1" client="site" method="upgrade">
    <files>
        <scriptfile>install.componentname.php</scriptfile> 
    </files>
</extension>

install.createmap.php

<?php 
$destination = JPATH_SITE."/images/mynewmap";
JFolder::create($destination);
?>

任何人都可以向我解释如何在 Joomla 3 中安装模块时将文件夹添加到媒体管理器 (root/images) 吗?

您需要一个 script.php 文件来执行您的安装任务:

https://docs.joomla.org/J3.x:Creating_a_simple_module/Adding_an_install-uninstall-update_script_file

这里是示例内容script.php:

<?php
// No direct access to this file
defined('_JEXEC') or die;

class mod_helloWorldInstallerScript
{
    function install($parent) 
    {
        echo '<p>The module has been installed</p>';
    }

    function uninstall($parent) 
    {
        echo '<p>The module has been uninstalled</p>';
    }

    function update($parent) 
    {
        echo '<p>The module has been updated to version' . $parent->get('manifest')->version . '</p>';
    }

    function preflight($type, $parent) 
    {
        echo '<p>Anything here happens before the installation/update/uninstallation of the module</p>';
    }

    function postflight($type, $parent) 
    {
        echo '<p>Anything here happens after the installation/update/uninstallation of the module</p>';
    }
}

它包含一个 class 和一些方法,因此您可以创建必要的文件夹结构。您想要扩展 postflight 方法。