@elise_daugherty
Phalcon's event system allows us to execute custom actions before or after certain events occur in our application. Here are the steps to use the event system in Phalcon:
1
|
$eventsManager = new PhalconEventsManager(); |
1 2 3 4 5 6 7 |
class SomeListener { public function logSomething(PhalconEventsEvent $event, PhalconMvcDispatcher $dispatcher, $data) { // your custom logic here } } |
1
|
$eventsManager->attach('some:event', new SomeListener()); |
1
|
$dispatcher->getEventsManager()->fire('some:event', $dispatcher, $data); |
Note: $dispatcher
is an instance of PhalconMvcDispatcher
that we can use to trigger events in our controller or view.
That's it! The listener's logSomething()
method will be executed when the some:event
event is triggered. You can add as many listeners as you need for different events in your application.