6.3.1 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.
Last Modified: 2010-03-22 13:45:47 Back to the top ↑
6.3.2 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
Last Modified: 2010-03-22 13:45:12 Back to the top ↑
6.3.3 Implementation
Most modules will perform three tasks in the following order:
- Include the
helper.phpfile 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: 2010-03-22 13:45:55 Back to the top ↑