开发者

Automatically create new folder under images on module installation

开发者 https://www.devze.com 2023-02-17 11:00 出处:网络
Is it possible for a Joomla exte开发者_开发知识库nsion to automatically create a folder (event) under images ->/images/events/ when the user installs the extension inside Joomla Administrator ?Inside

Is it possible for a Joomla exte开发者_开发知识库nsion to automatically create a folder (event) under images -> /images/events/ when the user installs the extension inside Joomla Administrator ?


Inside your component's xml file you will need to add in the following attribute:

<installfile>install.componentname.php</installfile> 

replace with the name of your component, this can be added just underneath the description attribute of your components install xml file.

Once this has been added you will need to create a file called "install.componentname.php", again replace componentname with the name of your component.

Inside this file add the following:

<?php

// no direct access
defined('_JEXEC') or die('Restricted Access');

// import joomla's filesystem classes
jimport('joomla.filesystem.folder');

// create a folder inside your images folder
if(JFolder::create(JPATH_ROOT.DS.'images'.DS.'events')) {
   echo "Folder created successfully";
} else {
   echo "Unable to create folder";
} ?>

Package this up and install, the install..php file should be at the top level of your zip archive. Lastly you will need to add this file to your components file list, just after the attribute add the following line:

<files>
<filename>install.componentname.php</filename>
</files>

If the folder is created successfully, it will say Folder created successfully.


you can specify a custom php script to be run at extension installation in your extension's manifest file [1, 2]. this script could create your folder /images/events/.

there are some differences in the installer between joomla 1.5 and 1.6:

1.5

  • you can only do this for components, not for modules or plugins
  • to specify your custom script, you use the <installfile/> section of the manifest file

1.6

  • besides for components, you can use a custom install script for modules and plugins, too
  • use the <scriptfile/> section of the manifest file

[...] i see another answer has been posted. have a look at it for 1.5; for 1.6, use <scriptfile/> and have a look at http://docs.joomla.org/Developers , especially http://docs.joomla.org/How_to_use_the_filesystem_package . the actual creation of the folder is left as an exercise for the reader.


<!-- Site Main Media File Copy Section -->
    <media destination="com_helloworld">
        <filename>image.png</filename>
        <filename>flash.swf</filename>
    </media>

http://docs.joomla.org/Components:xml_installfile

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号