richardhj/contao-model-events

v1.2.1 2019-11-11 11:07 UTC

This package is auto-updated.

Last update: 2024-12-11 22:16:45 UTC


README

Latest Version on Packagist Software License

This extension provides the DispatchModelEventsTrait that makes the following events available for your custom model:

Events implemented

PrePersistModelEvent

Triggered before persisting the model in the database. You can access the Model with the current data and the Model with the original data.

Row data can be modified at this point, when using setData().

PostPersistModelEvent

Triggered after persisting the model in the database. You can access the Model with the current data and the Model with the original data.

DeleteModelEvent

Triggered after the model has been deleted successfully. You can access the Model instance.

Usage

Implement the Trait in your custom model

use Contao\Model;

class MyTableModel extends Model
{

    use Contao\Model\DispatchModelEventsTrait;

    /**
     * Table name
     *
     * @var string
     */
    protected static $strTable = 'tl_my_table';
}

From now on, the above mentioned events get triggered on any save() and delete() action.