This is a multiple article series on how to create a module for Joomla! Version . You can navigate the articles in this series by using the navigation drop down menu.

Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (Articles in this series).

Introduction

Installing, updating and uninstalling a module may require additional operations that cannot be achieved by the basic operations described in the main xml file. Joomla offers a new approach to solve this problem. It consists in using a php script file containing a class using five methods:

preflight which is executed before install and update

install

update

uninstall

postflight which is executed after install and update

Creating the extension script file

Writing an extension script consists in declaring an class whose name is mod_ModuleNameInstallerScript with these 5 methods.

script.php

<?php// No direct access to this filedefined('_JEXEC')ordie;/** * Script file of HelloWorld module */classmod_helloWorldInstallerScript{/** * Method to install the extension * $parent is the class calling this method * * @return void */functioninstall($parent){echo'<p>The module has been installed</p>';}/** * Method to uninstall the extension * $parent is the class calling this method * * @return void */functionuninstall($parent){echo'<p>The module has been uninstalled</p>';}/** * Method to update the extension * $parent is the class calling this method * * @return void */functionupdate($parent){echo'<p>The module has been updated to version'.$parent->get('manifest')->version.'</p>';}/** * Method to run before an install/update/uninstall method * $parent is the class calling this method * $type is the type of change (install, update or discover_install) * * @return void */functionpreflight($type,$parent){echo'<p>Anything here happens before the installation/update/uninstallation of the module</p>';}/** * Method to run after an install/update/uninstall method * $parent is the class calling this method * $type is the type of change (install, update or discover_install) * * @return void */functionpostflight($type,$parent){echo'<p>Anything here happens after the installation/update/uninstallation of the module</p>';}}

In the update method we show the new version using $parent->get('manifest')->version. You can also redirect to a page of choice with $parent->getParent()->setRedirectURL('index.php?option=com_modules');.

Now you need to add a call to your script.php in the module xml file:
<scriptfile>script.php</scriptfile>

Content is available under Joomla! EDL unless otherwise noted.Joomla!® is a registered trademark of Open Source Matters, Inc.If you are experiencing technical issues with this website, please report it
.
Notice a content problem? Create an account
and fix it.