PostCreate, PostEdit and PostRemove logging to save on other database
PostCreate, PostEdit and PostRemove logging to save on other database
I want to PostEdit to save logging on other database and no save to same database !
function logChange ($db, $action, $id, $values) {
$db->insert('logs', array(
'user' => $_SESSION['user'],
'action' => $action,
'values' => json_encode($values),
'row' => $id,
'date' => date('d.m.Y')
));
}
...
->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();
Please help me and thank you very much.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Does the database connection held by
$db
have permission to write to the other database? If so, just useotherDb.logs
as the table name.If it doesn't have permission and you can't add it, then you would need another database connection resource (probably best to use just a regular plain old PDO resource rather than the Editor database abstraction layer).
Allan
Now, again and clarity:
Step by step:
1) Datatables.php - code:
2) Bootstrap.php - code:
3) config-database1.php - code:
4) config-database2.php - code:
5) staff-data.php - code:
Where I add PDO and PDO for insert on PostEdit?
Okay, so the
$db2
variable is the connection you want to use for the logging? In which case you don't need a plain PDO connection (presumably you are happy to use the EditorDatabase
class rather than a plain PDO reference).In which case you might use:
Then your
logChange
function will be passed the$db2
variable.Allan
I am happy.
SOLVED !
I ask you:
If click to data - open Editor form and logchange to save information, it is posible?
I'm afraid I don't quite understand the question. You are already using a
logChange
function to save the information. Is that not doing what you want?Allan
Information storage is fine when the feature works when you create or after formation, to update or upgrade, when you delete or after removal. That's okay. I just want to, when I click to read such information, then the function logChange stores information such as reading events. Does it?
PreCreate, PreEdit, PreRemove, PostCreate, PostEdit and PostRemove are all OK :-)
I ask you, is possible maybe: PreRead? PostRead?
I want logChange to save information for read row?
You are understand?
As of 1.6 there are
preGet
andpostGet
methods which are documented here.That sounds like a lot of data storage!
Allan
I understand for lot of data storage, but I want to test. Afraid after test:
Problem is: not working, table is showing: dialog error - tn/1
Thank you for solve problem - "preGet or postGet"
I have a version Editor 1.60.
What is the response from the server? Most likely there is an error being shown in it that would explain the issue.
Allan
This is solved problem. This error was for small error of syntax.