PHP event order

PHP event order

RagnarGrootKoerkampRagnarGrootKoerkamp Posts: 48Questions: 14Answers: 1
edited June 2016 in Editor

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

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin
    Answer ✓

    Hi,

    The pre events are indeed triggered prior to the database being queried for the data. The post events are triggered after. The reason for that is to allow the post event 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 the postEdit event 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.

    I stumbled upon the Join::set(false) method by luck.

    The API documentation for the PHP libraries is available here.

    in Editor/Field.php (line 330-331), SET_NONE and SET_BOTH should be the other way around.

    Thanks! Fix committed and will be in the next release.

    Allan

  • RagnarGrootKoerkampRagnarGrootKoerkamp Posts: 48Questions: 14Answers: 1

    Thanks, it's working now!

This discussion has been closed.