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

use*_*580 1 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>
Run Code Online (Sandbox Code Playgroud)

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

<cfdump var="#variables.this#"><br /><br /><br /><br /><br /><br />
<cfdump var="#this#">
Run Code Online (Sandbox Code Playgroud)

现在,如果你请求test.cfm,一切都很好,但当我删除onRequest方法Application.cfctest.cfm再次请求时,它抱怨"Element THIS is undefined in VARIABLES. ",我不知道为什么,有人能解释一下吗?十分感谢.

PS:

你可以添加尽可能多的功能集成Application.cfc,如onSessionStart,onSessionEnd,onApplicationStart,onApplicationEnd......,但是如果没有一个onRequest方法,你申请test.cfm并得到错误.我只是不知道为什么.

dwb*_*dwb 7

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

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

<cfdump var="#application#"/>
Run Code Online (Sandbox Code Playgroud)