Skip to content

Application CFC Integration

dskaggs edited this page Nov 15, 2012 · 1 revision

Model-Glue 3 has added support for new message broadcasts that can be used to emulate the behavior of the corresponding application event methods in Application.cfc: onApplicationStart, onSessionStart and onSessionEnd. These new messages are broadcast by the framework automatically, and can be used by adding the appropriate message listeners in any controller:

<controller id="Controller" type="myApplication.controller.Controller">
    <message-listener message="onApplicationStart" function="onApplicationStart" />
    <message-listener message="onSessionStart" function="onSessionStart" />
    <message-listener message="onSessionEnd" function="onSessionEnd" />
</controller>

And then adding the corresponding message listener function(s) to the controller CFC:

<cffunction name="onApplicationStart" access="public" output="false">
    <cfargument name="event" />

    <!--- Add your application start method logic here. --->
</cffunction>

<cffunction name="onSessionStart" access="public" output="false">
    <cfargument name="event" />

    <!--- Add your session start method logic here. --->
</cffunction>

<cffunction name="onSessionEnd" access="public" output="false">
    <cfargument name="event" />

    <!--- Add your session end method logic here. --->
</cffunction>

As with any Model-Glue broadcast, you may add message listeners to as many controllers as you like, and they will be fired in the order in which the controllers appear in the ModelGlue.xml file.

The onApplicationStart event is broadcast every time a Model-Glue application initializes, so it will be fired on every request if the application is in development mode.

In order to access the sessionScope structure that is supplied as an argument to the onSessionEnd event in Application.cfc, one can retrieve this value from the event argument of the message listener function:

<cfset sessionScope = arguments.event.getValue("sessionScope") />
Clone this wiki locally