GiriGiriPHP
home | about | download | how to


Flattr this
How to add an action
Any module folder
Adding an action basically consists of doing 3 things :

- Adding the action's key (any kind of alphanumeric string, like action_a) to the info file of the module. (info.php)

- Adding a case-switch block to the actions() method of the module.

- Assigning group permissions, (allow/disallow) for that action to the permission table, through the permissions manager in admin.

- Dropping in a template for that action, in templates folder (whichever you are using) of the module.

So, first, decide on a key for your action. Like, action_a. This will be the key you will send to the module to request that action.

Then, edit info.php in the module folder, and add the action key to the actions array, so system will know. Like:

$gb->modules['user']['actions'] = array(
'admin_index',
'action_a', <- added here
'signup_form'
);

After that, add your new action into the module (in this case, user module as the example), in its class.php file, by adding a case-switch block, as you see below :

switch ($action)
{
   //////////////////////////////////////////////////////////////////////
   //////////////////////////////////////////////////////////////////////
      case 'admin_index':
      .......... (various code present in this existing action) ......
      break;

      .......... (various other switch blocks (actions) like the above present in between) ......

   //////////////////////////////////////////////////////////////////////
   //////////////////////////////////////////////////////////////////////
      case 'action_a':
      .......... (your code for your action here !!!) ......

      .......... (add the below commands in order to process and build the output your action will do - mostly the below will be same for any action ) ......

      // Build the module template up till this stage
      $tp->build('user','user');
      // Build language of module
      $tp->build_lang('user','user');
      // Append it to page output.
      $tp->ins('T_PAGE_OUTPUT',$tp->str['user']);
      break;

} // Switch-case for actions end.

Replace the string 'user' with the key of the module you are adding an action to, above. Like, if you are adding it to groups, put in 'groups' string instead of 'user'.

Now, at this stage, go to the templatees/ folder for the module, and drop a plain, empty text file with the name of your action -> in this case, action_a.tpl. You dont need to add anything to this template file. The output of the action, will be appended to the page output with the

$tp->ins('T_PAGE_OUTPUT',$tp->str['user']);

command at the end of the action you added. But, you can. Any kind of image, form, html, javascript, whatever. That command is not mandatory, you can place a Key in the main page template you are using, and just assign the action's output to that key. You dont have to append it to any particular key in $tp->in['page'] stash.

Last, just go to the GiriGiri admin, and permissions module. Choose the module (in this case, user), and then choose your action, action_a from radio select boxes. Then, choose a group from the above group selector box, and then either choose Allow or Disallow, from the final select box. When you save this form, that group will be granted the permission you have given for that action. By default, if there are no permissions for allowing for any action, the system assumes no permission.

Done !