coldfusion - cflocation 是否调用 onRequest?
问题描述
我收到错误“transaction_types”未定义,并且无法理解原因。
我有application.cfc:
<cffunction name="onRequest" >
<cfargument name="targetPage" type="String" required=true/>
<cfinclude template="header.cfm">
</cffunction>
header.cfm 文件看起来像这样(每个文件都会调用 header,并且根据用户所在的目录有不同的子标题):
<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 并随后在目录/index.cfm 之前加载目录/subheader.cfm。cflocation 会绕过这个吗?
解决方案
您在 OnRequest 中包含在variables
Application.cfc 范围内设置变量的代码,然后稍后尝试在模板中引用。
一般而言,cfc 的变量范围,包括 Application.cfc,虽然是一种特殊情况,但不会传递到作为请求的一部分调用的模板。
如果您需要transaction_types
在 Application.cfc OnRequest 期间设置,是否在包含的模板中,并稍后在 index.cfm 中引用,则应在类似范围内完成,然后再按此方式request
引用。
子标题.cfm
<cfset request.transaction_types = ["a", "b", "c"] />
然后参考request.transaction_types
index.cfm 代码。
推荐阅读
- php - 如何通过 Laravel 路由中间件将多个参数传递给策略
- python - 如何复制数据框中的整行
- mysql - 在 IIS 中接收电子邮件并插入 MYSQL
- python - 在python中运行和清除不同的程序并清除控制台和变量
- react-native - 当 Modalize 打开时反应原生禁用向左滑动
- jpa - 使用安全 JDBC 通过用户/电子邮件和密码登录
- python - Python 异步下载证书链
- python - Python中的简单线性回归问题
- vaadin - Vaadin 14:尝试在对话框的后台打开页面,同时保持对话框打开
- amazon-web-services - 在哪里可以找到 AWS Lambda 的 dotnetcore3.1 运行时的源代码?