J3.x

Difference between revisions of "Creating a simple module/Adding an install-uninstall-update script file/es"

From Joomla! Documentation

< J3.x:Creating a simple module
Line 92: Line 92:
  
 
<div class="row">  
 
<div class="row">  
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Creating_a_simple_module/Adding_Auto_Update|Prev: Agregar actualización automática|class=expand success}}</div>
+
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Creating_a_simple_module/Adding_Auto_Update|Prev: Agregar Actualización Automática|class=expand success}}</div>
 
</div>
 
</div>
 
__NOTOC__
 
__NOTOC__

Revision as of 09:19, 29 August 2015

Other languages:
Bahasa Indonesia • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎中文(台灣)‎
Joomla! 
3.x
Tutorial
Crear un módulo simple

Esta es una serie de artículos múltiples sobre cómo crear un módulo para Joomla! Versión Joomla 3.x. Puedes navegar por los artículos en esta serie usando el menú desplegable de navegación.

Comienza con la Introducción y navega por los artículos de esta serie usando el botón de navegación en la parte inferior o en el cuadro de la derecha ("Artículos de esta serie").




Introducción

Instalar, actualizar y desinstalar un módulo puede requerir operaciones adicionales que no pueden ser alcanzadas por las operaciones básicas descritas en el archivo principal xml. Joomla ofrece un nuevo enfoque para resolver este problema. Consiste en utilizar un archivo de comandos de php que contiene una clase con cinco métodos:

  • comprobaciones que se ejecuta antes de instalar y actualizar
  • instalar
  • actualizar
  • desinstalar
  • comprobaciones que se ejecutan después de instalar y actualizar

Crear un archivo de secuencia de comandos de la extensión

Escribir una secuencia de comandos de la extensión consiste en declarar una clase cuyo nombre es mod _ NombreMóduloInstallerScript con estos 5 métodos.

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

En el método update nos muestran la nueva versión usando $parent->get('manifest')->version. También puede redirigir a una página de elección con $parent->getParent()->setRedirectURL('index.php?option=com_modules');.

Ahora lo que necesitas es agregar una llamada a tu script.php en el archivo xml del módulo: <scriptfile>script.php</scriptfile>