How to get additional data on the server-side postEdit event?
How to get additional data on the server-side postEdit event?
I'm using the logging example code on the server-side events page to create an activity log for my table.
This is the code:
->on( 'postEdit', function ( $editor, $id, $values, $row ) {
$editor->db()->insert( 'log', array(
'user' => $_SESSION['username'],
'action' => 'Edit users table row',
'values' => json_encode( $values ),
'row' => $id,
'when' => date('c')
);
} )
What I want is to get the column label on the table, not the column name on the database just because they are different. This is the section of the code:
'values' => json_encode( $values ),
Also, there are several fields from the edited record that i'd like to add, besides the row ID:
'row' => $id,
Like: 'row2' => $Name
or 'row3' => $employee_id
Any advice or suggestions are welcome!
Thank you
This question has an accepted answers - jump to answer
Answers
Hi,
If the names of the fields in the
$values
array is not what you want you would need to translate them either through a database lookup or perhaps a static map. You could potentially use theField->name()
and / or theField->db()
method if you have used the ability to define a different HTTP name from the database name for a field to do that translation.I'm not quite clear why you can't just add the code you suggested to the array? You'd need access to those variables of course and also
row2
etc would need to a column in the database.Allan
I tried to, but it seems I'm doing it wrong.
<b>Warning</b>: Missing argument 5 for {closure}() in <b>/home1/hdoadm/public_html/credenciales/examples/php/employees.php</b> on line <b>63</b><br />
<br />
<b>Notice</b>: Undefined variable: employee_id in <b>/home1/hdoadm/public_html/credenciales/examples/php/employees.php</b> on line <b>69</b><br />
{"error":"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'row2' cannot be null","data":[]}
You can't add an extra argument to the function call - Editor is the one that defines what arguments it passes in.
Without being able to see the full code, I can't say for sure, but can't you do something like:
Depending entirely on where the employee id is and what it is called of course. Is it in the row object?
Allan
Awesome. It worked perfectly! Thank you.