Creating Modules

This page covers the three files every module needs and the minimal code each one requires to work. By the end you'll have a module skeleton ready to install.

Every module lives somewhere inside the ./modules/ directory — that's where epesi looks for them. You can nest a module in subdirectories, and the module's name is built from that path. If this is your first module, put it in ./modules/Test/MyModule/; with that path, the module's name is Test/MyModule.

Inside that directory, create three files. Each one is named after the directory it lives in (MyModule in this example):

  • MyModule_0.php - the module's main file

  • MyModuleInstall.php - used during installation

  • MyModuleCommon_0.php - shared functions other modules can call

The trailing _0 is a version number, letting epesi upgrade each module selectively rather than all at once. Leave it at 0 for now — you don't need to worry about it yet.

Each of these files needs a small amount of boilerplate: mainly the class definitions epesi expects to find in them.

MyModule_0.php

<?php
defined("_VALID_ACCESS") || die('Direct access forbidden'); // This is a security feature.

class Test_MyModule extends Module { // Note how the class name reflects the module's path.

    public function body(){ // Here you will place the main code for the module.

    }
}
?>

There isn't much here yet, but this file usually ends up being the largest one in a module. The body() method runs whenever the module is displayed — more on that in a later page.

MyModuleInstall.php

<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');

class Test_MyModuleInstall extends ModuleInstall {

    public function install() {
        // Here you can place the installation process for the module
        return true; // Return true on success and false on failure
    }

    public function uninstall() {
        // Here you can place the uninstallation process for the module
        return true; // Return true on success and false on failure
    }

    public function info() {
        // Returns basic information about the module, shown in epesi Main Setup
        return array(   'Author'=>'<Place your name here>', 
                'License'=>'<Place type of the license here>', 
                'Description'=>'<Place description here>');
    }

    public function simple_setup() {
        // Indicates if this module should be visible in Main Setup's simple view
        return true; 
    }

    public function requires($v) {
        // Returns the list of modules and versions this module requires
        return array(); 
    }

    public function version() {
        // Returns the module's version name
        return array('0.1'); 
    }
}
?>

MyModuleCommon_0.php

<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');

class Test_MyModuleCommon extends ModuleCommon {

}
?>

Add simple, module-related functions to this class when other modules need to call them directly. If this file ends up empty, you can delete it.