J3.x

J3.x:Een eenvoudige module maken - Het toevoegen van een installatie-deïnstallatie-update script bestand

From Joomla! Documentation

< J3.x:Creating a simple module
This page is a translated version of the page J3.x:Creating a simple module/Adding an install-uninstall-update script file and the translation is 100% complete.
Other languages:
Bahasa Indonesia • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎中文(台灣)‎
Joomla! 
3.x
Handleiding
Een eenvoudige module maken

Dit is een serie artikelen over het ontwikkelen van een module voor Joomla! versie Joomla 3.x. U kunt navigeren binnen de artikelen in deze serie met behulp van het navigatie drop-down menu.

Begin met de Introductie en navigeer door de artikelen van de serie door middel van de navigatieknop onderaan of het vak rechts (Artikelen in deze serie). Er zitten 2 video's bij deze handleiding die u hier kunt zien Basic Joomla Module Development video 1 en Basic Joomla Module Development video 2.




Inleiding

Installeren, bijwerken en deïnstalleren van een module kunnen aanvullende acties vereisen die niet bereikt kunnen worden door de basis handelingen die worden beschreven in het .xml bestand. Joomla biedt een nieuwe aanpak om dit probleem op te lossen. Het bestaat in het gebruik van een PHP script bestand dat een class bevat met vijf functies:

  • preflight dat uitgevoerd wordt voor het installeren en de update
  • install
  • update
  • uninstall
  • postflight dat uitgevoerd wordt na installatie en update

Het maken van het extensie script bestand

Schrijf een extensie script door het declareren van een class waarvan de naam is mod_ModuleNameInstallerScript met deze 5 functies.

script.php

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

/**
 * Script file of HelloWorld module
 */
class mod_helloWorldInstallerScript
{
	/**
	 * Method to install the extension
	 * $parent is the class calling this method
	 *
	 * @return void
	 */
	function install($parent) 
	{
		echo '<p>The module has been installed.</p>';
	}

	/**
	 * Method to uninstall the extension
	 * $parent is the class calling this method
	 *
	 * @return void
	 */
	function uninstall($parent) 
	{
		echo '<p>The module has been uninstalled.</p>';
	}

	/**
	 * Method to update the extension
	 * $parent is the class calling this method
	 *
	 * @return void
	 */
	function update($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
	 */
	function preflight($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
	 */
	function postflight($type, $parent) 
	{
		echo '<p>Anything here happens after the installation/update/uninstallation of the module.</p>';
	}
}

In de update methode tonen we het nieuwe versienummer met $parent->get('manifest')->version. U kunt ook verwijzen naar een pagina naar keuze met $parent->getParent()->setRedirectURL('index.php?option=com_modules');.

Denk eraan en oproep toe te voegen naar uw script.php in het .xml bestand van de modules: <scriptfile>script.php</scriptfile>