richardhj/contao-model-events


Keywords
contao
License
Other

Documentation

Contao Model Events

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.