The Sahana Code Base

This page provides an overview for programmers of the organization of the Sahana source code.

Back to outline


Sahana Modules

Sahana is a modular and extensible system. Different software components, or modules, each reside in their own folder in the mod/ directory. Each module has a short name, which is the name of the module's folder, and is used to refer to the module in code. For example, the Volunteer Management module's short name is vm. Sahana comes with many modules pre-installed. You can see this by looking at the contents of the mod/ folder of a fresh install.

$ ls mod
cms    cs   gis    hr    mpr  or    rms   skel  vm
admin  cr   dvr    home  ims  msg   pref  rs    sync  vol

The File Structure of a Sahana Module

The skel module is the skeleton module, a simple module that serves as an example and a framework for module developers. It contains code to display a simple message, populate Sahana's menu navigation system, and display an HTML form with various types of inputs. The skeleton module is a good place to start when creating a new module.

Within the skeleton module there are 3 files:

$ ls mod/skel

When Sahana loads a module, it looks for the file in the module's folder. The and files store administration and configuration info about the module. It's not strictly necessary to have these files, but it's a good convention.

The File

The file is inserts the module into Sahana's main menu:

 * Gives the nice name of the module
$conf['mod_skel_name'] = _("Skeleton Module");

 * Gives the priority order in the main menu when listed
$conf['mod_skel_menuorder'] = 21; 

The File

The bulk of the skeleton module is contained in This file contains several functions but the two main functions are:


The naming convention in Sahana is to name functions with shn_{module name}_{function name}(). This is to prevent colliding function names for different modules, as they share the same namespace.

The mainmenu() Function

The shn_skel_mainmenu() and shn_skel_default() functions are special. The mainmenu() function is called by Sahana to populate the navigation menu on the left side of the page:

function shn_skel_mainmenu()
    global $global;
    $module = $global['module'];

    // Create the module menu
    shn_mod_menuopen(_('Skeleton Module'));

    shn_sub_mod_menuopen(_('Sub Menu'));
    shn_sub_mod_menuitem('mio',_('Menu Item 1'));
    shn_sub_mod_menuitem('mit',_('Menu Item 2'));

    shn_sub_mod_menuopen(_('Sub Menu 2'));


    // include the main menu so that the user can navigate outside the module
    include $global['approot'].'/inc/';

The default() Function

The default() function is the function that gets called when a module is first loaded:

function shn_skel_default()

    global $global;

<div id="home">

<h2><?= _('Skeleton Module'); ?></h2>
<p><?= _('This is a description of the module that we typically
give on the first page with it\' features listed below')?>
<?= _('Features include:');?></p>
    <li><?=_('Give a description of the features')?></li>
    <li><?=_('Feature 2')?></li>


We will use the examples in the skeleton module to create our own helloworld module.

Back to outline