Changes between Version 1 and Version 2 of HowTos/ApplicationCFCIntegration
- Timestamp:
- 05/21/09 17:41:23 (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
HowTos/ApplicationCFCIntegration
v1 v2 1 = Application.cfc Integration with M G3 =1 = Application.cfc Integration with Model-Glue 3 = 2 2 3 You can add listeners: 3 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: 4 4 5 {{{ 5 <message-listener message="onApplicationStart(SessionStart/SessionEnd" function=".." /> 6 <controller id="Controller" type="myApplication.controller.Controller"> 7 <message-listener message="onApplicationStart" function="onApplicationStart" /> 8 <message-listener message="onSessionStart" function="onSessionStart" /> 9 <message-listener message="onSessionEnd" function="onSessionEnd" /> 10 </controller> 6 11 }}} 7 12 8 http://localhost:8500/modelgluesamples/applicationcfc/ 13 And then adding the corresponding message listener function(s) to the controller CFC: 9 14 10 I'm an example of using the new "onApplicationStart", "onSessionStart", and "onSessionEnd" broadcasts. 15 {{{ 16 <cffunction name="onApplicationStart" access="public" output="false"> 17 <cfargument name="event" /> 11 18 12 According to its controller, this app has 1 active session. If you open a second type of browser or browse from another computer, you should see this number go up when you reload. 19 <!--- Add your application start method logic here. ---> 20 </cffunction> 13 21 14 To listen for any of these events, just add a message listener tag to any of your controllers: 22 <cffunction name="onSessionStart" access="public" output="false"> 23 <cfargument name="event" /> 24 25 <!--- Add your session start method logic here. ---> 26 </cffunction> 27 28 <cffunction name="onSessionEnd" access="public" output="false"> 29 <cfargument name="event" /> 30 31 <!--- Add your session end method logic here. ---> 32 </cffunction> 33 }}} 34 35 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. 36 37 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. 38 39 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: 40 15 41 {{{ 16 <controller id="Controller" type="modelgluesamples/applicationcfc.controller.Controller"> 17 <message-listener message="onApplicationStart" function="onApplicationStart" /> 18 <message-listener message="onRequestStart" function="getSessionCount" /> 19 <message-listener message="onSessionStart" function="onSessionStart" /> 20 <message-listener message="onSessionEnd" function="onSessionEnd" /> 21 </controller> 42 <cfset sessionScope = arguments.event.getValue("sessionScope") /> 22 43 }}} 23 Like any other message broadcast, you can have as many listener functions as you desire.
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)