home *** CD-ROM | disk | FTP | other *** search
Wrap
<!------------------------------------------------------------- This example shows how CFLOCK can be used to guarantee the consistency of data updates to variables in the Application, Server, and Session scopes. You should copy the following code into an Application.cfm file in the snippets directory. ---------------------------------------------------------------> <HTML> <HEAD> <title>Define Session and Application Variables</title> </HEAD> <BASEFONT FACE="Arial, Helvetica" SIZE=2> <BODY bgcolor="#FFFFD5"> <H3>CFAPPLICATION Example</H3> <P>CFAPPLICATION defines scoping for a ColdFusion application and enables or disables the storing of application and/or session variables. This tag is placed in a special file called Application.cfm that is run before any other CF template in a directory where the Application.cfm file appears. This is a read- only example to ensure that you create your own Application.cfm file according to the needs of your site. <!------------------------------------------------------------- <CFAPPLICATION NAME="ETurtle" SESSIONTIMEOUT="60" SESSIONMANAGEMENT="yes"> <!------------------------------------------------------------- Initialize the session and application variables that will be used by E-Turtleneck. Use the session lock for the session variables. The member variable sessionID creates the session name for you. ---------------------------------------------------------------> <CFLOCK Name="#session.sessionID#" timeout="30" Type ="Exclusive"> <CFIF NOT IsDefined("session.size")> <CFSET session.size = ""> </CFIF> <CFIF NOT IsDefined("session.color")> <CFSET session.color = ""> </CFIF> </CFLOCK> <!---------------------------------------------------------------- Use the application lock for the application variable. This variable keeps track of the total number of turtlenecks sold. The application lock should have the same name as specified in the CFAPPLICATION tag. -------------------------------------------------------------------> <CFLOCK Name="application.applicationName" Timeout="30" Type="Exclusive"> <CFIF NOT IsDefined("application.number")> <CFSET application.number = 1> </CFIF> </CFLOCK> <CFLOCK Name="application.applicationName" Timeout="30" Type ="ReadOnly"> <CFOUTPUT> E-Turtleneck is proud to say that we have sold #application.number# turtlenecks to date. </CFOUTPUT> </CFLOCK> ---------------------------------------------------------------> <!--- End of Application.cfm ---> <HEAD> <TITLE> CFLOCK Example </TITLE> </HEAD> <BASEFONT FACE="Arial, Helvetica" SIZE=2> <BODY bgcolor="#FFFFD5"> <H3>CFLOCK Example</H3> <!--------------------------------------------------------------------- <CFIF IsDefined("form.submit")> <!----------------------------------------------------------------- Lock session variable sessionID. Note that the sessionID member variable becomes the order number. -------------------------------------------------------------------> <CFLOCK Name="#session.sessionID#" timeout="30" Type="ReadOnly"> <CFOUTPUT> Thank you for shopping E-Turtleneck. Today you have chosen a turtleneck in size <b>#form.size#</b> and in the color <b>#form.color#</b>. Your order number is #session.sessionID#. </CFOUTPUT> </CFLOCK> <!----------------------------------------------------------------- Lock session variables to assign form values to them. To lock session variables, you should get the session ID with the sessionID member variable. -------------------------------------------------------------------> <CFLOCK Name="#session.sessionID#" timeout="30" Type="Exclusive"> <CFPARAM Name=session.size Default=#form.size#> <CFPARAM Name=session.color Default=#form.color#> </CFLOCK> <!------------------------------------------------------------------ Lock application variable application.number to find the total number of turtlenecks sold. If you do not know the name of the application, you can use the member variable applicationName to get it. -------------------------------------------------------------------> <CFLOCK Name="#application.applicationName#" Timeout="30" Type="Exclusive"> <CFSET application.number = application.number + 1> </CFLOCK> <CFELSE><!--- Show the form only if it has not been submitted. ---> <FORM ACTION="cflock.cfm" METHOD="POST"> <P>Congratulations! You have just selected the longest wearing, most comfortable turtleneck in the world. Please indicate the color and size that you wish to buy.</P> <table cellspacing="2" cellpadding="2" border="0"> <tr> <td>Select a color.</td> <td><SELECT TYPE="Text" NAME="color"> <OPTION>red <OPTION>white <OPTION>blue <OPTION>turquoise <OPTION>black <OPTION>forest green </SELECT> </td> </tr> <tr> <td>Select a size.</td> <td><SELECT TYPE="Text" NAME="size" > <OPTION>XXsmall <OPTION>Xsmall <OPTION>small <OPTION>medium <OPTION>large <OPTION>Xlarge </SELECT> </td> </tr> <tr> <td>Press Submit when you are finished making your selection.</td> <td><INPUT TYPE="Submit" NAME="submit" VALUE="Submit"> </td> </tr> </table> </FORM> </CFIF> -------------------------------------------------------------------> </HTML>