Event Handling

Table of Contents

Event Naming
Triggering Events
Including Data With An Event
Handling Data Returned by Observers
Listening for Events
Observer Name and Location
Implementing the Observer
Registering An Observer
List of Triggered Events

Recite CMS allows you to write event-driven scripts. These are scripts that are executed only when certain events occur.

For example, if you want to run a custom script after a user is deleted you can easily achieve this by "listening" for the /module/users/user/postdelete event.

There are many different events that occur that you can listen for. Additionally, you can trigger your own events that other scripts can listen for. All of this is covered in this section.

In Recite CMS, a script that listens to an event is called an observer.

Event Naming

Events are named similar to a filesystem path. That is, it is made of several segments, each separated by a slash. This mechanism is used to easily map observers to event names.

For example, the event that is triggered when a user is created is called /module/users/users/postinsert. It doesn't matter whether or not there is a slash at the start or event of the event name.

If you attempt to trigger an event with a name that doesn't follow this style, the event will not be triggered.

For the purposes of this chapter we'll use a sample event name called /some/sample/event.