Download the PHP package justcoded/yii2-event-listener without Composer
On this page you can find all versions of the php package justcoded/yii2-event-listener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justcoded/yii2-event-listener
More information about justcoded/yii2-event-listener
Files in justcoded/yii2-event-listener
Package yii2-event-listener
Short Description Yii2 Event Listener
License BSD-3-Clause
Informations about the package yii2-event-listener
Yii2 Event Listener
Simple event listeners registration component and base abstract classes to implement Linstener or Observer.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
Component Setup
To use the Event Listener Component, you need to configure the components array in your application configuration:
and add component name to bootstrap array
Usage
Listeners
Listener is a single action, which can be performed on some event. To register a listener you need to create a simple class:
After that you need to register it within a component inside 'listeners' config array:
Observers
Observer is a class, which can subscribe to several events of the same model. To create an
Observer you need to extend it from a basic Observer class and create events()
method and methods to
handle these events.
Example:
After that you need to register it within a component inside 'observers' config array:
ActiveRevordObserver
Package also contains a specific class called ActiveRecordObserver. This class already declared all ActiveRecord events an methods to process them:
- inserting()
- inserted()
- updating()
- updated()
- deleting()
- deleted()
- validating()
- validated()
- refreshed()
- initialized()
Example: