1

I have a coldfusion site with an application.cfm. It has a cfapplication defined in it:

<cfapplication name="FhaApp" clientmanagement="no"
           sessionmanagement="yes" sessiontimeout="#createTimeSpan(0,0,360,0)#">

<cflock timeout="120" name="#session.sessionID#" type="exclusive">
<cfcookie name="CFID" value="#session.CFID#" >
<cfcookie name="CFTOKEN" value="#session.cftoken#" >
</cflock>
<cfparam name="session.fromwhere" default="">
<cfif #cgi.SCRIPT_NAME# contains 'default-partner-'>
    <cfif not ISDEFINED("cookie.fromwhere")>
<cfcookie name="fromwhere" value="#right(cgi.SCRIPT_NAME,         (len(cgi.SCRIPT_NAME)-1))#" expires="30">
    <cfset session.fromwhere = #right(cgi.SCRIPT_NAME,(len(cgi.SCRIPT_NAME)-1))#>
    </cfif> 
 </cfif>

 <cfset datasourcename="fha47">

 <cfparam name="application.dsn" default="fha47">

 <cfparam name="session.loggedin" default="false">
 <cfparam name="session.ppcid" default="101">
 <cfparam name="session.cid" default="FHA">

I want to add another cfapplication that looks like this:

<cfapplication name = "QSvalues" 
sessionTimeout = "#CreateTimeSpan(0,0, 0, 60)#" 
sessionManagement = "yes">


<cflock scope = "Session" 
timeout = "30" type = "Exclusive">
<cfif NOT IsDefined("session.prop_st")>
    <cfset session.prop_st = "">
</cfif>
<cfif NOT IsDefined("session.prop_zip")>
    <cfset session.prop_zip = "">
</cfif>
<cfif NOT IsDefined("session.address")>
    <cfset session.address = "">
</cfif>
<cfif NOT IsDefined("session.email")>
    <cfset session.email = "">
</cfif>
<cfif NOT IsDefined("session.fname")>
    <cfset session.fname = "">
</cfif>
<cfif NOT IsDefined("session.lname")>
    <cfset session.lname = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_1")>
    <cfset session.pri_phone_1 = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_2")>
    <cfset session.pri_phone_2 = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_3")>
    <cfset session.pri_phone_3 = "">
</cfif>
</cflock>

<cflock scope = "Application" timeout = "30" type = "Exclusive">
<cfif NOT IsDefined("application.number")>
    <cfset application.number = 0>
</cfif>
</cflock>

My question is, can you define two separate cfapplication in the main application.cfm?

post.72
  • 333
  • 4
  • 14
  • No. It probably would not cause a syntax error, but the last one would win out. What are you trying to accomplish? – Leigh Feb 06 '12 at 19:46

3 Answers3

3

I'm not entirely sure why you would want or need the second cfapplication; it's not really clear from your code or explanation. I think you could probably put another one in there, but it would likely override the previous one.

Besides, in your code all you're doing is writing to the application scope.. that's not really declaring another cfapplication.

A couple of tips though... your big cfif area for the session values, just use cfparam:

<cfparam name="session.prop_st" default="">

That way if it doesn't already exist, it will be created.

Also, if you're using the latest ColdFusion, you don't need to cflock around session scopes. You should be locking around the application scope settings, but since you're setting them in Application.cfm, it's kinda silly.. I would use another scope, like the request scope.

On your cfif cgi.script_name, you don't need # signs around that variable. The only times you need them are when they're quoted or are being outputted in a cfoutput (or when used with Evaluate() to create dynamic variables).

I hope this helps.

RobG
  • 1,751
  • 2
  • 11
  • 7
  • 1
    Interesting that this answer was chosen as the solution, and yet did not even attempt to address the specific question posted. – Jake Feasel Feb 06 '12 at 20:07
  • Rob, each `` tag does indeed start a new application; both application scopes will exist, however only the currently-named application for a given request will be accessible. However if one goes back to the first application, it'll still be there. Bottom line, I don't think this works the way the OP wanted. – Adam Cameron Feb 07 '12 at 17:38
1

Well, you can do this, technically. The result would be that the Application, client and session scopes associated with the first tag call would be available only until the second tag call. At that point, all subsequent references to those scopes would refer to the context defined by the latter tag. It's not too many cases where doing this is a great idea, however.

Jake Feasel
  • 16,785
  • 5
  • 53
  • 66
0

Use Sean Corfield's approach to create an Application.cfc in a sub-folder which extends your root Application.cfc.

https://stackoverflow.com/a/307441/11047

Your root Application.cfc will contain all of the primary application and session variables needed. Your sub-directory's Application.cfc will contain all of the application and session variables for your "QSvalues" application. However these variables will sit in application.qsValues and session.qsValues.

application.qsValues.number, not application.number. session.qsValues.prop_st, not session.prop_st.

Doing this, you can have as many "sub-applications" as you want, but they'll all exist within a single APPLICATION.NAME.

Community
  • 1
  • 1
Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
  • Note the OP is asking about .cfm not .cfc – Jake Feasel Feb 06 '12 at 20:09
  • Ok, that's true. But that begs the question, is it possible to convert it to an Application.cfc? If so, then the answer is relevant. – Adrian J. Moreno Feb 06 '12 at 21:07
  • I actually doubt that you can have multiple application references within Application.cfc - `cfapplication` isn't actually used there, the application pool is established instead via the invocation of the component, and setup with the `this` scope, like so: `this.name="FooApp"` vs. `` – Jake Feasel Feb 06 '12 at 21:59
  • You only define application.name in the root Application.cfc, the other Application.cfc files only deal with application and session variables specific to that folder's application. Those variables are usually put into a struct specific to that "sub-application" so that when you dump the application or session struct, you see which variables were created by which application. – Adrian J. Moreno Feb 06 '12 at 23:03