get table name in dv hooks

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
globaldrip8
Posts: 27
Joined: 2015-12-19 03:59

get table name in dv hooks

Post by globaldrip8 » 2019-06-24 13:57

hello,do u know function how to get table name in the hooks

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1891
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: get table name in dv hooks

Post by jsetzer » 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
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

globaldrip8
Posts: 27
Joined: 2015-12-19 03:59

Re: get table name in dv hooks

Post by globaldrip8 » 2019-06-27 05:59

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

Post Reply