【发布时间】:2020-07-13 17:42:04
【问题描述】:
我收到一个错误“transaction_types”未定义,并且无法理解原因。
我有 application.cfc:
<cffunction name="onRequest" >
<cfargument name="targetPage" type="String" required=true/>
<cfinclude template="header.cfm">
</cffunction>
header.cfm 文件看起来像这样(每个文件都会调用头文件,并且根据用户所在的目录有不同的子头文件):
<cfinclude template="#GetDirectoryFromPath(Arguments.targetPage)#subheader.cfm" />
我遇到问题的目录有两个文件,index.cfm 和 subheader.cfm
subheader.cfm,第一行
<cfset transaction_types = ["a", "b", "c"] />
index.cfm 的一部分,我认为问题可能是 cflocation,但我不确定:
<cfif structKeyExists(url, "something") >
-- some database work is done here --
<cflocation url="index.cfm">
</cfif>
--further down on this page, transaction_types is used
我设置页面时认为 transaction_types 将在目录/index.cfm 加载的任何时候定义,因为应用程序文件总是加载 header.cfm 和随后的 directory/subheader.cfm,然后再加载 directory/index.cfm。 cflocation 会绕过这个吗?
【问题讨论】:
-
我相信你是正确的帕特里克。我认为
cflocation呼叫不会通过正常的请求处理。它不调用onRequest方法。他们已经记录了它与onRequestEnd方法的行为不同,因为它没有被调用 BUT 它确实调用了onAbort方法。来自文档:使用 cfabort、cflocation 或 cfcontent 标签时,会在 OnRequestEnd 上调用 OnAbort 方法。 对cflocation的调用也会停止处理当前页面。 -
说了这么多,我相信您
cflocation访问的页面应该经过正常的请求处理。所以说你使用cflocation到'page2.cfm'。我认为 page2.cfm 将调用onRequest方法,但是当cflocation标签触发时,初始页面请求会停止。 -
发生错误时,正在处理哪个页面 - index.cfm 或 subheader.cfm?
-
part of index.cfm, and I think the issue might be the cflocation...index.cfm脚本正在定位到 自身 ...这是一个错字吗? FWIW,您可以自己测试 cflocation 是否调用 OnRequest。创建一个单独的 Application.cfc 并实现 OnRequest。每当调用该方法时,在 OnRequest 方法内部都会显示一些文本,例如:writeOutput("onRequest called");使用 cflocation 调用创建一个测试 cfm 页面。运行它,看看“onRequest called”是否出现在屏幕顶部。 -
AFAIK 当
cflocation标签执行时,它会停止当前处理的请求,触发Application.cfc 的onAbort方法,然后将302 HTTP 状态代码(默认情况下)发送回用户的浏览器。这反过来指示浏览器对该 302 状态消息中包含的 URL 发出新请求。这应该从新的 URL 重新开始这个过程。
标签: coldfusion coldfusion-10 application.cfc cflocation