-
Notifications
You must be signed in to change notification settings - Fork 3
Context object
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.
Context exposes the following methods:
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 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.
This method starts the event handling routine. You can use this method if handleRequest() doesn't suit your needs, but a better approach is to employ a RequestStrategy.
Arguments:
- The target (string)
- The event type (string)
- Data that is available to the event (struct)
The method returns the Response object that contains all generated content.
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:
- The
Taskto be executed - The phase: 'start', 'before', 'after', 'end', or 'event'
- The target
- The event type: only required for tasks in the 'event' phase
You can create tasks with the factory methods that Context provides, see below.
Task is an interface, so you can also create your own specific implementations.
Sets the default target.
Sets the default event type.
The target and event defaults are used if no target and/ or event type is given, or if an event is dispatched that has no tasks defined for it (and implicit tasks is off). You can use this for the welcome page, which is probably the most common use case. Another use case is for handling unknown events gracefully, such as when people start typing in urls themselves.
The default event is dispatched also if an event is dispatched during the request handling cycle.
If an existing target is provided, but the event type is not defined, any start, before, after and end tasks are executed, since these are independent of the event type.
By default, both default target and event type are an empty string, which means this feature is off.
Sets whether to use CFlow conventions if an event is dispatched that is not defined. If false, and such an event is dispatched, nothing happens. Otherwise, when true, Tasks are created according to the framework convention that are then executed.
Sets the (dot delimited) mapping that is used to find controllers. You don't have to set this, you can also provide the complete path in the configuration.
Sets the (slash delimited) mapping that is used to find views (.cfm templates). Like the controller mapping, this is optional.