Changes between Version 1 and Version 2 of HowTos/ApplicationCFCIntegration

Show
Ignore:
Timestamp:
05/21/09 17:41:23 (17 years ago)
Author:
cfgrok (IP: 64.30.223.5)
Comment:

Created new version of page

Legend:

Unmodified
Added
Removed
Modified
  • HowTos/ApplicationCFCIntegration

    v1 v2  
    1 = Application.cfc Integration with MG3 = 
     1= Application.cfc Integration with Model-Glue 3 = 
    22 
    3 You can add listeners: 
     3Model-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 
    45{{{ 
    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> 
    611}}} 
    712 
    8 http://localhost:8500/modelgluesamples/applicationcfc/ 
     13And then adding the corresponding message listener function(s) to the controller CFC: 
    914 
    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" /> 
    1118 
    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> 
    1321 
    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 
     35As 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 
     37The 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 
     39In 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 
    1541{{{ 
    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") /> 
    2243}}} 
    23 Like any other message broadcast, you can have as many listener functions as you desire.