Book Image

CakePHP 2 Application Cookbook

By : James Watts, Cake Software Foundation, Inc.
Book Image

CakePHP 2 Application Cookbook

By: James Watts, Cake Software Foundation, Inc.

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Managing event priorities


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.

Getting ready

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...