EventsWhen working with complex data, it can often be useful to perform some additional action when Editor updates the database based on information from the client-side. Consider for example the following use case: - Modifying the Editor instance or form fields based on that action being taken
- Deleting files from the file system when rows are removed
- Logging information to a database about an action that a user has taken.
to name just a few! To make this possible, the PHP Editor class provides an event listener / callback option similar to the events that the client-side Javascript will trigger. Listening for eventsEvents listeners can be added using the Editor->on() method which takes two arguments: - The event name to listen for
- A callback function which defines the action to take. The arguments passed to the callback are event dependent. The return value for the
pre* named events can be used to cancel actions (see below), while the other event handlers to not use any returned value.
Multiple listeners for the same event can be added simply by calling the Editor->on() method multiple times. The events will be executed in the same sequence that they were added. Available eventsThe Editor class will trigger the following events - the arguments passed into the function are also documented: preGet (cancellable) - Triggered immediately prior to reading row data from the database (since 1.6)$editor - The Editor instance that triggered the event$id - Row id being selected if only a single row is to be selected (i.e. after an edit). Otherwise this value will be null indicating that all rows will be selected.
postGet - Triggered immediately after row information has been read from the database (since 1.6)$editor - The Editor instance that triggered the event$data - Data array of rows that have been read from the database$id - Row id being selected if only a single row is to be selected (i.e. after an edit). Otherwise this value will be null indicating that all rows will be selected.
preCreate (cancellable) - Triggered immediately prior to creating a new row$editor - The Editor instance that triggered the event$values - The values submitted by the client-side
writeCreate - Data has been written to the database, but not yet read back, allowing the database to be updated before the data is gathered to display in the table (since 1.6.2)$editor - The Editor instance that triggered the event$id - ID of the row that was created$values - The values submitted by the client-side
postCreate - Triggered immediately after a new row has been created$editor - The Editor instance that triggered the event$id - ID of the newly created row$values - The values submitted by the client-side$row - The newly created row's data, as read from the database
preEdit (cancellable) - Triggered immediately prior to updating an existing row$editor - The Editor instance that triggered the event$id - ID of the row to be edited$values - The values submitted by the client-side
writeEdit - Data has been written to the database, but not yet read back, allowing the database to be updated before the data is gathered to display in the table (since 1.6.2)$editor - The Editor instance that triggered the event$id - ID of the row to be edited$values - The values submitted by the client-side
postEdit - Triggered immediately after an existing row has been updated$editor - The Editor instance that triggered the event$id - ID of the row that has been edited$values - The values submitted by the client-side$row - The updated row's data, as read from the database
preRemove (cancellable) - Triggered immediately prior to deleting an existing row$editor - The Editor instance that triggered the event$id - ID of the row to be deleted$values - The values submitted by the client-side (i.e. the row's data set)
postRemove - Triggered immediately after a row has been deleted$editor - The Editor instance that triggered the event$id - ID of the row that has been deleted$values - The values submitted by the client-side (i.e. the row's data set)
preUpload (cancellable) - Triggered immediately prior to a file upload being processed (since 1.6.2)$editor - The Editor instance that triggered the event$data - Data submitted by the upload form
postUpload - Triggered after a file has been uploaded and information about it read from the database (since 1.6.2)$editor - The Editor instance that triggered the event$id - ID of the database record for the uploaded file (or the file's unique name if a database record is not used)$files - The file information that has been read from the database$data - Data submitted by the upload form
Please note that for multi-row creation, editing and deletion, the events are triggered once for each row.
|