Adding triggers to actions
Xataface 0.6.1 adds some triggers to actions so that the developer can define custom functionality to be performed after an action has successfullly taken place.
Xataface 0.6.1 adds a number of triggers that are useful for adding flow control to applications. They are as follows:
- after_action_new
- Called after a new record is successfully created. This is different than the afterInsert trigger as that trigger is called immediately after a record is inserted, even if it is inserted as part of a batch of inserts such as when a related record is being added. This trigger is only called when the ‘new’ action is successfully performed.
- after_action_edit
- Called after a record is successfully edited on the edit form. This is different than the afterUpdate trigger as that trigger is immediately called after a record is updated, even if it is updated as part of a batch of updates, such as when a related record is being removed. This trigger is only called when the ‘edit’ action is successfully performed.
- after_action_new_related_record
- Called after a new related record is successfully created (-action=new_related_record).
- after_action_existing_related_record
- Called after an existing related record is successfully added (-action=existing_related_record).
Examples
<?php
class tables_Personal {
/**
* Forwards the user to a different url after a new record is created, if the -redirect
* parameter is passed to the form as a GET variable.
*/
function after_action_new(){
if ( @$_REQUEST['-redirect']){
header('Location: '.$_REQUEST['-redirect']);
exit;
}
}
?>