Jump to content

Example module.inc file: Difference between revisions

From NusaATK
No edit summary
Mjs (talk | contribs)
No edit summary
Line 32: Line 32:
* The url that should displayed when the user clicks the menu item. ''This can be any valid url.''
* 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.
A third and a fourth paramerer can be added as well.


  function getMenuItems()
  function getMenuItems()
  {
  {
   $this->menuitem("groupadmin", dispatch_url("users.group", "admin"), '''"main", array("users.group", "admin")''');
   $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 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 can be three things:
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.
* 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.

Revision as of 17:19, 26 August 2008

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.