Hi,
I'm running the Premium versionand have questions about an additional audit trail table I'd like to write each time a record is update in the grid.
I need to log the column name, the value before … I use the on_update function … it works fine but I don't know how to get the column name and the value before.
Does someone can help ?
Thanks a lot
Benjamin
I guess you already know, it's doable with on_insert / on_update event callbacks.
In those events handler functions, you get $data array that has key names as columns
in this way: $data["params"]["field"]
For before value, you will need to run an additional sql, that will fetch data in on_update.
e.g. select * from table where id = $data["id"]
Yes, I use the on_update function in which I insert a line in Audit table.
That work but I don't know how to get the column header that has changed.
I tried print_r($data) and/or phpgrid_error("blabla") but then I have an error 500 … difficult to see what is happening.
Thanks
in event handler try this …
function my_insert($data)
{
ob_start();
print_r($data);
$str = ob_get_clean();
phpgrid_error($str);
}
This would print the $data as error message so you can debug.
Nothing is printed … or maybe it is printed behind of <iframe> …
I tried a "brutal" solution by added an "exit;" … nothing more 🙁
I get the value before with an additional "select …" but always do not hva the column label (header) ..
You get $data array of this format:
/*
These comments are just to show the input param format
$data => Array
(
[client_id] => 2
[params] => Array
(
[client_id] => 2
[name] => Client 2
[gender] => male
[company] => Client 2 Company
)
)
*/
The params key contains column name with new posted value.
You can run foreach loop to get both in event handler.
i need to create an audit trail table to keep track of add and edit transactions along with user, date and time of transactions.
is there an example in the package i can review to help me get started?
thank you.
Hello Kim
Sample is not currently available. However i can help in some code snippets.