Reputation: 2577
I'm getting an error "transaction_types" is undefined, and having trouble understanding why.
I have application.cfc:
<cffunction name="onRequest" >
<cfargument name="targetPage" type="String" required=true/>
<cfinclude template="header.cfm">
</cffunction>
header.cfm file looks like this (header is called on every file and there is a different subheader depending on the directory the user is in):
<cfinclude template="#GetDirectoryFromPath(Arguments.targetPage)#subheader.cfm" />
The directory I'm having a problem with has two files, index.cfm and subheader.cfm
subheader.cfm, the first line
<cfset transaction_types = ["a", "b", "c"] />
part of index.cfm, and I think the issue might be the cflocation, but I'm not sure:
<cfif structKeyExists(url, "something") >
-- some database work is done here --
<cflocation url="index.cfm">
</cfif>
--further down on this page, transaction_types is used
I set the page up thinking transaction_types will be defined any time directory/index.cfm loads, since the application file always loads header.cfm and subsequently directory/subheader.cfm before directory/index.cfm. Does cflocation bypass this?
Upvotes: 0
Views: 149
Reputation: 4694
You are including code in OnRequest that is setting variables in variables
scope of Application.cfc and then trying to reference in template later.
The variables scope of a cfc in general, including Application.cfc specifically though a special case, does not carry through to the templates that are called as part of the request.
If you need to set transaction_types
during Application.cfc OnRequest, in included templates or not, and reference in index.cfm later, then it should be done in scope like request
and then referenced later as such.
subheader.cfm
<cfset request.transaction_types = ["a", "b", "c"] />
Then refernece as request.transaction_types
in index.cfm code.
Upvotes: 0