Log table for errors
Log table for errors
Restful Web Services
Posts: 202Questions: 49Answers: 2
in Editor
I currently use the server side events to log changes, as described here:
function logChange ( $db, $action, $id, $values ) {
$db->insert( 'staff-log', array(
'user' => $_SESSION['username'],
'action' => $action,
'values' => json_encode( $values ),
'row' => $id,
'when' => date('c')
) );
}
Editor::inst( $db, 'staff' )
->fields(
Field::inst( 'first_name' ),
Field::inst( 'last_name' ),
Field::inst( 'position' ),
Field::inst( 'email' ),
Field::inst( 'office' )
)
->on( 'postCreate', function ( $editor, $id, $values, $row ) {
logChange( $editor->db(), 'create', $id, $values );
} )
->on( 'postEdit', function ( $editor, $id, $values, $row ) {
logChange( $editor->db(), 'edit', $id, $values );
} )
->on( 'postRemove', function ( $editor, $id, $values ) {
logChange( $editor->db(), 'delete', $id, $values );
} )
->process( $_POST )
->json();
However, it would be really useful to also log errors associated with datatables events. For example, the information which appears if you have ->debug( true )
enabled or JSON response errors.
Has anyone else tried/achieved this? I am just at the thinking it through stage so was wondering if anyone had any experience?
Thanks
This discussion has been closed.
Answers
Rather than:
Use:
Allan
Hi Allan,
Thanks for your prompt reply. Would this work or am I missing
$editor->db()
and$id
if I try and log the change after->data();
like this:Thanks
This does work,
But I currently don't have the $id of the item being edited or created in my scope and it also saves the
SELECT
queries as oppose to just errors.Should the
$id
var be available somewhere in the scope and can I access just errors, will they be in a nested element in the debug array. It's a little tricky to test as I haven't figured out how to force an error!Thanks
Chris