Documentation

Controllers

Overview

Unlike components, which potentially can have multiple controllers, modules do not have a controller class. As such, the module directory structure doesn't include a /controllers subdirectory or controller.php. Instead, the setting of parameters, inclusion of any necessary files, and the instantiation of the module's view are done within the mod_{ModuleName}.php file.

Directory Structure & Files

The controller is stored in the same directory as the module file itself and must be named the same (the file extension being the obvious difference).

/hubzero
  /modules
    /{ModuleName}
      /tmpl
        default.php
      helper.php
      mod_{ModuleName}.php
      mod_{ModuleName}.xml

Implementation

Most modules will perform three tasks in the following order:

  • Include the helper.php file which contains the class to be used to collect any necessary data
  • Invoke the appropriate helper class method to retrieve any data that needs to be available to the view
  • Include the template to display the output

Here are the contents of mod_listnames.php:

<?php
// No direct access
defined('_JEXEC') or die('Restricted access');

// Include the helper file
require_once(dirname(__FILE__).DS.'helper.php');

// Get a parameter from the module's configuration
$userCount = $params->get('usercount');

// Get the items to display from the helper
$items = modListNamesHelper::getItems($userCount);

// Include the template for display
require(JModuleHelper::getLayoutPath('mod_listnames'));

Last modified: