Triggers / Callbacks
Trigger Other Operation (Added in v2.4)
Notes:- Perform other operation like Insert/Update data in other table directly.
- Many times, you want to perform insert/update/delete operation in other table than main table also. For example, after entering employee leave date in "leaves" table, you might want to update total leaves taken by that employee in employee table also. One way is to do this is using the callback function, but you have to write quite a lines of code there.
- Now same thing can be achieved using the setTriggerOperation() function. You can specify tablename, column data, where data, type of operation and event to perform this operation.
$pdocrud = new PDOCrud();
$pdocrud->setTriggerOperation("student", array("total_attendance" => array("type" => "fixed", "val" => 10)),
array(), "insert", "after_insert");
//$pdocrud->setTriggerOperation("student", array("total_attendance" => array("type" => "last_insert_id")),
//array(), "insert", "after_insert");
//$pdocrud->setTriggerOperation("student", array("total_attendance" => array("type" => "array_data", "val" => "student_id")),
//array(), "insert", "before_insert");
//$pdocrud->setTriggerOperation("student", array("total_attendance" => array("type" => "fixed", "val" => 12)),
//array("student_id"=> array("type" => "array_data", "val" => "student_id")), "update", "after_update");
echo $pdocrud->dbTable("attendance")->render();
Callback Functions
$pdocrud = new PDOCrud();
//Add callback function "beforeloginCallback" on before_select event
$pdocrud->addCallback("before_select", "beforeloginCallback");
echo $pdocrud->dbTable("users")->render();
// Available events are
//This 'beforeloginCallback' function must be added on script/pdocrud.php file
// e.g. before data submission encrypt user password
function beforeloginCallback($data, $this) {
$data["data"]["user_pass"]= md5($data["data"]["user_pass"]);
return $data;
}