关于Application.cfc中onRequest方法的coldfusion问题

时间:2009-07-09 07:50:51

标签: coldfusion scope application.cfc

我被冷凝问题阻止,任何建议都表示赞赏。现在我要解释我的问题。


我的网站根目录中有Application.cfc,其内容如下:

<cfcomponent output="false">
    <cffunction name="onRequest" returnType="void">
        <cfargument name="thePage" type="string" required="true">
        <cfinclude template="#arguments.thePage#">
    </cffunction>
</cfcomponent>

我还有一个cfm模板,其名称为test.cfm,其内容如下所示:

<cfdump var="#variables.this#"><br /><br /><br /><br /><br /><br />
<cfdump var="#this#">

现在,如果您请求test.cfm,一切正常,但当我删除onRequest中的Application.cfc方法并再次请求test.cfm时,它会抱怨{{1}我不知道为什么,有人可以解释一下吗?非常感谢。

PS:

您可以在"Element THIS is undefined in VARIABLES. "中添加任意数量的功能,例如Application.cfconSessionStartonSessionEndonApplicationStart ..., 但如果没有onApplicationEnd方法,则请求onRequest并获取错误。我只是不知道为什么。

2 个答案:

答案 0 :(得分:7)

这是因为 this 范围是指cfc实例。当您在application.cfc 中包含test.cfm时,此指的是application.cfc实例。直接调用test.cfm 时,不存在,因为请求没有通过application.cfc,所以你不在cfc实例中。

不确定您要做什么,但您可能不想在cfc之外使用 this 。如果要从test.cfm转储应用程序范围,请执行以下操作:

<cfdump var="#application#"/>

答案 1 :(得分:3)

从onRequestStart方法返回true将为您加载页面。正如dwb所说,你的'this'指的是Application.cfc,因为你已经从其中一个方法中包含了它。如果需要引用应用程序,请使用应用程序范围而不是“this”,除非您确实在Application.cfc中。