Page 1 of 1

get table name in dv hooks

Posted: 2019-06-24 13:57
by globaldrip8
hello,do u know function how to get table name in the hooks

Re: get table name in dv hooks

Posted: 2019-06-24 15:01
by jsetzer
Hi,

for a common logging-function I did the following couple of months ago:

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);
        // ...
}
Variable $table should contain the table name. You can adjust the function to your needs, for example return $table.

Integration
  1. Put my function into your code
  2. from one of your hook functions call log($data);
  3. within my function check the variable $table
It should work if you call it from any hook-function following the naming convention...

{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

Re: get table name in dv hooks

Posted: 2019-06-27 05:59
by globaldrip8
jsetzer wrote:
2019-06-24 15:01
Hi,

for a common logging-function I did the following couple of months ago:

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);
        // ...
}
Variable $table should contain the table name. You can adjust the function to your needs, for example return $table.

Integration
  1. Put my function into your code
  2. from one of your hook functions call log($data);
  3. within my function check the variable $table
It should work if you call it from any hook-function following the naming convention...

{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
thank you
i fixed it with my own way like this

$table_file=basename($_SERVER['SCRIPT_FILENAME']);
$tablename=substr($table_file,0, -9);

$tablename is the table name

hope this solution will help other in the future