-
Notifications
You must be signed in to change notification settings - Fork 3
Controllers
Controllers are the components that know where to get data from, and pass this on to the view for rendering. So these components should ideally be light weight and contain little logic. However, that's not something that CFlow fusses about.
There is only one instance of each controller. If ColdFusion had the notion, they would be static components. This means that the controller has no state pertaining to the request at hand. Its state is shared among all requests during the life of the context instance (which keeps them).
Each controller must extend cflow.request.Controller. Extending Controller gives your controller the ability to dispatch events using dispatchEvent().
This method expects 2 arguments: an event type (no target!), and an event object (usually the current event). The event that is dispatched in the event handling system has the same target as the event object that is passed. All data from the passed event object is forwarded to the new event.
dispatchEvent() returns a boolean, which indicates if the event was successful (true) or canceled (false).
Event handlers are public methods that require one argument: an event object. The method implementation then uses this event object to do what it's good at, which is hopefully exactly one well defined thing. If needed, it can put its results back on the event object, which makes it available for subsequent tasks.