Jump to content

Triggers

From NusaATK
Revision as of 21:30, 17 December 2007 by bahtiar (talk | contribs) (Pre triggers)

You can use the following triggers on a node:

  • preAdd
  • postAdd
  • preUpdate
  • postUpdate
  • preDelete
  • postDelete

to perform various tasks after or before an action has been executed.

These triggers take only 1 argument, which is an array with the record.

Pre triggers

If the trigger is a pre- trigger, you can make the argument to be a pointer and you can adjust the record before it is added/updated/deleted.

Pre-trigger returning false does not necessarily halt the action being performed (because of backwards compatability). To actually halt the action, use the triggerError-function. Doing so will add an entry in the record called 'atkerror'. Upon detecting this, the action will halt. And the message in the atkerror entry will be displayed as an error. For more information on the triggerError function, please see the API documentation on the function.

an example for having the preAdd and preUpdate triggers run the same code:

  function preAdd(&$record) 
  {
    $this->makeNames($record);
    return true;
  } 

  function preUpdate(&$record) 
  {
    $this->makeNames($record);
    return true;
  } 

  function makeNames(&$record)  
  {
    $record["full_name"] = $record["names_slot_1"] . $record["names_slot_2"];
  }

Listeners

Note that triggers are superseded by Listeners, a more flexible concept as Listeners can be applied at runtime.