问题:
我在同一个文件夹中有2个文件:
我的index.cfm为空,下面是我的application.cfc
代码:
<cfcomponent>
<cffunction name="onApplicationStart">
<cfapplication name="TimeHistory" clientmanagement="No" sessionmanagement="No" setclientcookies="Yes" />
<cflock scope="application" type="exclusive" timeout=10>
<cfset application.test = "xxxxxxxxxxxxxx">
</cflock>
<cfreturn true />
</cffunction>
<cffunction name="onRequestStart">
<cfdump var="#application#" label="before">
<cfif structKeyExists(URL, "restart")>
<cfset onApplicationStart()>
</cfif>
<cfdump var="#application#" label="after">
<cfabort>
</cffunction>
</cfcomponent>
如您所见,我在test
中设置了application scope
变量。
当我使用?restart
URL查询参数调用页面时,这是输出:
网址: ../index.cfm?restart
接下来,我删除了?reset
URL查询参数并加载了页面,这是输出:
网址: ../index.cfm
问题:
它是否应该将变量设置为第一个调用的一部分,然后保留以供将来调用?我怎么能这样做?
答案 0 :(得分:4)
根据 + Leigh 的评论,我修改了现在可以使用的代码。留在这里作为解决方案。谢谢Leigh:)
<cfcomponent>
<cfscript>
this.name = "TimeHistory";
this.clientmanagement= "no";
this.sessionmanagement = "no";
this.setClientCookies = "no";
this.setDomainCookies = "no";
</cfscript>
<cffunction name="onApplicationStart">
<cflock scope="application" type="exclusive" timeout=10>
<cfset application.test = "xxxxxxxxxxxxxx">
</cflock>
<cfreturn true />
</cffunction>
<cffunction name="onRequestStart">
<cfdump var="#application#" label="before">
<cfif structKeyExists(URL, "restart")>
<cfset onApplicationStart()>
</cfif>
<cfdump var="#application#" label="after">
<cfabort>
</cffunction>
</cfcomponent>