Book Image

CakePHP 2 Application Cookbook

Book Image

CakePHP 2 Application Cookbook

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

Using a detector


Detectors are used by the framework to analyze a request and make quick assertions about the incoming data or petition. CakePHP provides a set of default request detectors, such as post, ajax, or ssl. However, you can easily extend the available detectors using CakeRequest::addDetector(). There are four different types of detectors that you can create:

  • Environment Value Comparison: This compares a value from env() for equality with the given value

  • Pattern Value Comparison: This compares a value from env() with a regular expression

  • Options-based Comparison: This uses a list of options to create a regular expression (options will be merged for subsequent calls to add an already defined options-based detector)

  • Callback: This uses a callable type to handle the comparison (the callback function receives the request object as the first and only argument)

We'll focus on the callback detector here, as it's by far the most powerful.

Getting ready

For this recipe, we'll define a controller...