Skip to content
neoneo edited this page Jan 25, 2012 · 8 revisions

Within CFlow, the Context object stores all information about events and makes object instances, such as controllers, available to executing tasks.

All object instances, except Event and Response instances are 'static', and thus cached by Context. These static objects therefore live as long as the Context object lives. Usually, you would create an instance of Context in onApplicationStart(), but basically it's up to you how you handle Context instances.

The Context exposes the following methods:

Response handleRequest()

This is a default request handling implementation, that gathers variables in the url and form scopes, and dispatches the corresponding event. If there are target and event variables present in those scopes, then those variables define the event target and type. If they are not present, which happens for instance with the initial request to your application, the default target and default event are used. You can set these using setDefaultTarget() and setDefaultEvent().
The method returns the Response object that contains all generated content.

Response handleEvent(required string, required string, optional struct)

This method starts the event handling routine. Use this method if handleRequest() doesn't suit your needs.

Arguments:

  1. The target (string)
  2. The event type (string)
  3. Data that is available to the event (struct)

The method returns the Response object that contains all generated content.

register(required Task, required string, required string, required string)

Registers a Task to be executed for a given target and event, during a given phase. Use this method if you don't want to configure using the default XML dialect.

Arguments:

  1. The Task to be executed
  2. The phase: 'start', 'before', 'after', 'end', or 'event'
  3. The target
  4. The event type

Clone this wiki locally