get table name in dv hooks
Posted: 2019-06-24 13:57
hello,do u know function how to get table name in the hooks
A place where AppGini users can exchange ideas and help each other.
https://forums.appgini.com:443/phpbb/
https://forums.appgini.com:443/phpbb/viewtopic.php?f=7&t=3097
Code: Select all
function log($data) {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
$caller = $trace[1];
$functionname = $caller['function'];
list($table, $time, $action) = explode('_', $functionname);
// ...
}
thank youjsetzer wrote: ↑2019-06-24 15:01Hi,
for a common logging-function I did the following couple of months ago:
Variable $table should contain the table name. You can adjust the function to your needs, for example return $table.Code: Select all
function log($data) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); $caller = $trace[1]; $functionname = $caller['function']; list($table, $time, $action) = explode('_', $functionname); // ... }
Integration
It should work if you call it from any hook-function following the naming convention...
- Put my function into your code
- from one of your hook functions call log($data);
- within my function check the variable $table
{TABLENAME} {underscore} {before|after} {underscore} {insert|update|delete}
...for example
myTableName_before_update
Attention
If you have tablenames containing "_" (underscore) you will have to modify my code.
Should be a good starting point anyway!
Kind Regards,
Jan