post.72
post.72

Reputation: 333

Can you have multiple cfapplications in an application.cfm?

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?

Upvotes: 1

Views: 1546

Answers (3)

Adrian J. Moreno
Adrian J. Moreno

Reputation: 14859

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.

Upvotes: 0

Jake Feasel
Jake Feasel

Reputation: 16955

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.

Upvotes: 1

RobG
RobG

Reputation: 1821

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.

Upvotes: 3

Related Questions