Version 3, last updated by gnomeontherun at 23 Mar 19:16 UTC
One of the powerful features of the Nooku Framework are events.
Controller events
Before and after any controller action, the framework checks for any callbacks that have been registered. These can be used for many purposes; authentication, access control etc or to carry out secondary actions. The.action callback must return a boolean. TRUE allows the command chain to continue, while FALSE terminates the command chain and prevents further actions, so if a before.add callback returns FALSE then the record will not be added.
The standard controller events are:
before.display after.display
before.edit after.edit
before.add after.add
before.delete after.delete
To implement one of the events, they should be registered in the controller constructor:
class ComSectionsControllerSection extends ComDefaultControllerDefault
{
/**
* Constructor
*
* @return void
*/
public function __construct(KConfig $config)
{
parent::__construct($config);
//Register callbacks
$this->registerCallback(array('before.delete'),array($this,'isEmpty'));
$this->registerCallback(array('after.add') ,array($this,'copyRecords'));
}
/**
* Callback
*
* @return boolean
*/
public function isEmpty(KCommandContext $context)
{
[your code here]
return (bool) $result;
}
KCommandContext contains the relevant data that the callback needs:
$context->data the submitted data
$context->result the row that was updated/inserted - this will only appear in after. events