Application.CFC变量不可用

时间:2014-05-26 11:36:59

标签: coldfusion application.cfc

在application.cfc中我定义了一个必须在整个会话中可用的变量。

<cfcomponent>
 <cfset this.applicationTimeout = createTimeSpan(0,4,0,0)>
    <cfset this.sessionManagement = true>
    <cfset this.setClientCookies  = true>
    <cfset this.sessionTimeout    = createTimeSpan(0,0,90,0)>
    <cfset this.setdomaincookies  = true>

    <cfset this.myVar = "Hello">
</cfcomponent>

我尝试了几种方法来获取.cfm中的myVar,但无济于事。

Approach 1: <cfoutput>#myVar#</cfoutput>
Approach 2: <cfoutput>#session.myVar#</cfoutput>
Approach 3: <cfoutput>#application.myVar#</cfoutput>

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:10)

您将Application.cfc的{​​{1}}范围设置与您自己的this范围变量放在一起令人困惑。

看看Ben Nadel的Application.cfc tutorial

您基本上希望将application放入application.myVar

OnApplicationStart()

然后,您应该可以在应用程序中将其引用为<cfcomponent> <cfset this.applicationTimeout = createTimeSpan(0,4,0,0)> <cfset this.sessionManagement = true> <cfset this.setClientCookies = true> <cfset this.sessionTimeout = createTimeSpan(0,0,90,0)> <cfset this.setdomaincookies = true> <cffunction name="OnApplicationStart"> <cfset application.myVar = "Hello"> </cffunction> </cfcomponent>