Application.cfc中onRequest方法的coldfusion问题
我因冷融合问题而受阻,任何建议都表示赞赏。 现在让我描述一下我的问题。
我的网站根目录中有一个 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
中添加任意多个函数,例如onSessionStart
、onSessionEnd
、onApplicationStart
、<代码>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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 this 范围引用了 cfc 实例。 当您在 application.cfc 中包含 test.cfm 时,this 指的是 application.cfc 实例。 当您直接调用 test.cfm 时,this 不存在,因为请求未经过 application.cfc,因此您不在 cfc 实例内。
不确定您想要做什么,但您可能不想在 cfc 之外使用这个。 如果您想从 test.cfm 转储应用程序范围,只需执行以下操作:
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:
从 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.