Membuat modul sederhana/Menambahkan file skrip install-uninstall-update
From Joomla! Documentation
Ini adalah seri artikel mengenai cara membuat modul untuk Joomla! Versi . Anda dapat menelusuri artikel-artikel yang terdapat di dalam seri ini melalui menu dropdown.
Mulai dari Pendahuluan, lalu telusuri artikel-artikel di dalam seri ini melalui tombol navigasi di bagian bawah atau dari kotak di samping (Artikel dalam seri ini)
Pendahuluan
Memasang, mengupdate dan melepaskan modul bisa saja membutuhkan pengoperasian tambahan yang tidak dapat dicapai oleh pengoperasian dasar seperti dijelaskan di file xml utama. Joomla menawarkan pendekatan baru untuk menyelesaikan masalah ini. Terdiri dari file skrip php yang mengandung kelas dengan lima metode:
- preflight yang dieksekusi sebelum install dan update
- install
- update
- uninstall
- postflight yang dieksekusi setelah install dan update
Membuat file skrip ekstensi
Menulis sebuah skrip ekstensi yang mengandung deklarasi kelas bernama mod_ModuleNameInstallerScript dengan 5 metode ini.
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>';
}
}
Di dalam metode update, kami menunjukkan versi baru melalui $parent->get('manifest')->version
. Anda bisa mengarahkan ke sebuah halaman pilihan dengan cara $parent->getParent()->setRedirectURL('index.php?option=com_modules');
.
Sekarang, anda perlu menambahkan sebuah pemanggilan ke script.php anda yang ada di file xml modul:
<scriptfile>script.php</scriptfile>