Jump to content

Example module.inc file

From NusaATK
Revision as of 17:19, 26 August 2008 by Mjs (talk | contribs)

Every module you add to an ATK application follows some basic principles.

Create a directory, where the name is equal to the module name. For example, if you're going to create a module 'users', name the directory 'users'. It's best to place it in the modules/ subdir of your application.

In the directory, you place your node files. A module does not necessarily have to have any nodes, but most modules will consist of one or more nodes.

The module file is the most important part of the directory, as it will define the module. This file should be called 'module.inc' and should contain the following code:

<?php

  class mod_users extends atkModule
  {

     function getNodes()
     {
        registerNode("users.group", array("admin", "add", "edit", "delete"));
     }

     function getMenuItems()
     {
        $this->menuitem("groupadmin", dispatch_url("users.group", "admin"));
     }

  }

?>

This function takes two parameters:

  • The name of the menuitem (‘groupadmin’ in this case)
  • The url that should displayed when the user clicks the menu item. This can be any valid url.

A third and a fourth parameter can be added as well.

function getMenuItems()
{
  $this->menuitem("groupadmin", dispatch_url("users.group", "admin"), "main", array("users.group", "admin"));
}

The third parameter, $parent, determines whether the menu item is a first- or second-level menu item. If $parent is absent or "main", the menu item appears at the top level. If $parent is a string, then the menu item appears as a sub-menu of the named menu item.

The fourth parameter controls menu item visibility. (i.e. who has access to the menu item.) If true, then the menu item is always displayed; if false it's never displayed. If it's an array, the first element of the array must be a node (identified by modulename.nodename notation), the second element is an action. The third can be a node again, the fourth an action, and so on. If the user has the right to perform one of these actions, he will see the menu-item. In this case, the menu is displayed if the user has the ‘admin’ right on the 'users.group' node.