AtkTriggerListener

From Achievo/ATK Wiki

Jump to: navigation, search

Classname: atkTriggerListener

API docs

List of other documented ATK classes

atkTriggerListener can be used to add listeners to node that get executed when an event happens on a record from that node (typically updates, deletes etc.). They are different from atkActionListeners: atkActionListeners are typically tied to a screen based action (e.g. updating a record by posting a form), while atkTriggerListeners are lower level, i.e. they not only get called when someone posts a form, but even when somebody calls updateDb() programmatically.

So in general, if you want to do things when a record is updated, atkTriggerListener would be the better choice.

Example use

  atkimport("atk.utils.atktriggerlistener");
 
  class MyListener extends atkTriggerListener
  {
      public function preUpdate( &$record )
      { 
          // do some code....
          return true;
      }
  }

It is important to return true from triggers; returning false indicates to ATK that something went wrong, and the whole transaction that this trigger was part of will then be rolled back.

Then, add the listener to the node using:

  $node->addListener(new MyListener());

See also

Personal tools
Navigation