PHP event order
PHP event order
RagnarGrootKoerkamp
Posts: 48Questions: 14Answers: 1
I would like to keep a changelog of some fields in my table, so I use a setup similar to the one here: https://editor.datatables.net/manual/php/events#Logging-changes.
Besides, I would like to show the changelog to the user in some way, so (in reference to the example) I joined the staff-log table to the staff table using a direct link with writing set to false (Mjoin(..)->set(false)). This is working quite well, except for one thing:
It seems that the data (for the edited row) that the server returns to the client is queried before the postCreate/postEdit events are invoked. Hence, the changelog that is submitted to the client will always be one change behind. Would it be possible to fire the post events right after editing the database, but before querying?
I understand that this might break code, or might not be the intended way of using this event. If so, could you point me to the lines where I would need to change things (i.e. fire a custom event).
PS: I stumbled upon the Join::set(false) method by luck. An error message hinted me to Field::set(false) method, but some documentation for this would be nice.
Oh, and in Editor/Field.php (line 330-331), SET_NONE and SET_BOTH should be the other way around.
This question has an accepted answers - jump to answer
Answers
Hi,
The
preevents are indeed triggered prior to the database being queried for the data. Thepostevents are triggered after. The reason for that is to allow thepostevent to modify the data that has been retrieved.Perhaps an additional event would be useful allowing the database to be updated. In Editor.php search for
function _update. You'll be able to see where thepostEditevent is triggered, and just before it where the data set is obtained using_get(). You could insert your event in there.This sounds like a useful addition. I've made a note for future releases.
The API documentation for the PHP libraries is available here.
Thanks! Fix committed and will be in the next release.
Allan
Thanks, it's working now!