When a new event is dispatched in CakePHP, all the listeners which match the event name that are attached to the event manager where the event was dispatched will be triggered to process the event in order. Sometimes, we need to ensure that a specific order is followed when several listeners are triggered for a specific event. This can be done through the event manager API. We also have the ability to stop the event propagation and force the rest of the listeners to be ignored after the current listener finishes.
In this recipe, we look at how you can control the event dispatch process to keep your events executing accordingly.
We'll continue to use our
packages table for this recipe. If you don't have it, create it with the following SQL statement:
CREATE TABLE packages ( id INT NOT NULL AUTO_INCREMENT, recipient VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, created DATETIME, modified DATETIME, PRIMARY KEY(id) );
Also, make sure that...