Application.cfc中onRequest方法的coldfusion问题

发布于 2024-07-26 07:07:07 字数 1109 浏览 3 评论 0原文

我因冷融合问题而受阻,任何建议都表示赞赏。 现在让我描述一下我的问题。


我的网站根目录中有一个 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,一切正常,但是当我删除Application.cfc中的onRequest方法时>并再次请求test.cfm,它抱怨“Element THIS is undefined in VARIABLES.”,我不知道为什么,有人可以解释一下吗? 万分感谢。

ps:

您可以在Application.cfc中添加任意多个函数,例如onSessionStartonSessionEndonApplicationStart、<代码>onApplicationEnd..., 但如果没有 onRequest 方法,您请求 test.cfm 并收到错误。 我只是不知道为什么。

i was blocked by a coldfusion problem, any suggestions are appreciated. now lemme decribe my problem.


i have an Application.cfc in my website root, the content in it is as follows:

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

and also i have a cfm template of which the name is test.cfm, it's content is listed as follows:

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

now if you request the test.cfm, everything is ok, but when i delete the onRequest method in Application.cfc and request test.cfm again, it complaints that "Element THIS is undefined in VARIABLES. ", i don't know why, can anybody explain it? great thanks.

ps:

you can add as many functions into Application.cfc, such as onSessionStart, onSessionEnd, onApplicationStart, onApplicationEnd...,
but if there is not a onRequest method, you request test.cfm and get error. i just don't know why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜访吸血鬼 2024-08-02 07:07:07

这是因为 this 范围引用了 cfc 实例。 当您在 application.cfc 中包含 test.cfm 时,this 指的是 application.cfc 实例。 当您直接调用 test.cfm 时,this 不存在,因为请求未经过 application.cfc,因此您不在 cfc 实例内。

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

<cfdump var="#application#"/>

It's because the this scope refers to a cfc instance. When you include test.cfm from within application.cfc this refers to the application.cfc instance. When you call test.cfm directly this does not exist because the request did not go through application.cfc, so you're not inside a cfc instance.

Not sure what you were trying to do, but you probably don't want to use this outside of a cfc. If you want to dump the application scope from test.cfm just do this instead:

<cfdump var="#application#"/>
洒一地阳光 2024-08-02 07:07:07

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

Returning true from the onRequestStart method will load the page for you. As dwb stated your 'this' is referring to to the Application.cfc because you have included it from within one of the methods. If you need to refer to the Application use the application scope not 'this', unless you really are inside of the Application.cfc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文