Jump to content

Example module.inc file

From NusaATK
Revision as of 07:36, 5 October 2006 by Jeroenvs (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 paramerer can be added as well.

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

Note: if we want to specify the fourth parameter, we can’t skip the second and the third. Therefore, you can now see that we put the 'groupadmin' menu-item in the main menu.

The fourth parameter can be three things:

  • True: menu item is always displayed
  • False: menu-item is never displayed.
  • An array with node/action pairs:

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.