如果我的 application.cfc 中有组件级属性,那么每次页面出现时都会对它们进行评估,还是仅在创建应用程序时对它们进行评估?
<cfcomponent>
<cfscript>
this.name = "WARM2_Demo";
this.applicationTimeout = CreateTimeSpan(1,0,0,0);
this.setClientCookies = true;
this.setDomainCookies = false;
this.sessionManagement = true;
this.sessionTimeout = CreateTimeSpan(0,0,30,0);
this.clientManagement = false;
this.scriptProtect = true;
this.appDirectory = getDirectoryFromPath(getCurrentTemplatePath());
this.fileSeparator = createObject("java","java.lang.System").getProperty("file.separator");
....
</cfscript>
<cffunction name="OnApplicationStart" returntype="boolean">
<cfscript>
setupApplication();
return true;
</cfscript>
</cffunction>
....
</cfcomponent>
最佳答案
Application.cfc 的伪构造函数执行每个请求。
基本上,每个请求都会在幕后创建一个 Application.cfc 实例,并且该实例化的行为就像任何其他 CFC 实例化一样:伪构造函数位 - CFCOMPONENT 标记内的内容,但没有任何 CFFUNCTION/函数声明 - 是运行。
运行伪构造函数后,将运行任何适当的事件处理程序/拦截器方法,例如:onRequestStart()。
注意:您可以自己轻松地进行测试,只需在其中输出一些内容即可。它会在每个请求时显示在屏幕上(使其成为 getTickCount() 或 createUuid() 调用,以便您可以看到它的变化)。
关于coldfusion - Application.cfc 中的组件级属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589580/