I was horsing around and figured it would be nice to move my application variables into a table that can be loaded onApplicationStart.
我正在四处奔波,并认为将我的应用程序变量移动到可以加载到应用程序启动的表中会很好。
My intent is to allow ANT to roll out the app, and change a few settings in the database and the proverbial presto..
我的意图是允许ANT推出应用程序,并更改数据库中的一些设置和众所周知的预设。
In my test code, the application.cfc has a simple query to call all the variable names and then a cfloop to set each variable within the application scope as application.varname.
在我的测试代码中,application.cfc有一个简单的查询来调用所有的变量名,然后是一个cfloop来将应用程序范围内的每个变量设置为application.varname。
There is no error reported onApplicationStart .. however trying to reference the variables gives an undefined type error.
在ApplicationStart上没有报告错误..但是尝试引用变量会给出未定义的类型错误。
My spider senses tell me this is something small and obvious... any ideas?
我的蜘蛛感觉告诉我这是一个小而明显的东西......任何想法?
Thanks!!
Update 1 : It seems what I'm looking at is setting dynamic variable names and the fact that they are application variables don't seem to have much impact..
更新1:看起来我正在看的是设置动态变量名称以及它们是应用程序变量似乎没有太大影响的事实。
http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm
4 个解决方案
#1
I do not know if the author was advocating that syntax or merely demonstrating that it works, as a point of interest.
我不知道作者是在提倡这种语法还是只是证明它有效,作为一个兴趣点。
Personally, I prefer array notation. I think it helps promote good scoping habits.
就个人而言,我更喜欢数组符号。我认为这有助于促进良好的范围生活习惯。
<!--- array notation --->
<cfset scope["staticName"& dynamicPortion] = "some value">
<!--- example 1 --->
<cfset variables["baseName"& x] = "oh brother">
<!--- example 2 --->
<cfset variables["baseName#x#"] = "oh brother">
#2
The answer to my question was to set dynamic variable names by quoting the names..
我的问题的答案是通过引用名称来设置动态变量名称。
<!--- Loop over the girls and alter the values. --->
<cfloop index="intGirl" from="1" to="3">
<!--- Randomly pick 1 (true) or 0 (false). --->
<cfif RandRange( 0, 1 )>
<!--- Set the dynamic variable naming used quoted evaluation. --->
<cfset "Girl#intGirl#" = "super sexy" />
</cfif>
</cfloop>
More here...
http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm
#3
use cfloop + cfset not cfoutput
使用cfloop + cfset而不是cfoutput
#4
If I'm reading your question correctly, you're saying that you're setting the application variables inside of a cfoutput tag?
如果我正确地阅读了您的问题,您是说您在cfoutput标签内设置了应用程序变量?
Are you using cfoutput like
你在使用cfoutput吗?
<cfoutput query="queryName">
<!--- Setting code in here --->
</cfoutput>
You should use cfloop rather than cfoutput
你应该使用cfloop而不是cfoutput
<cfloop query="queryName">
<cfset application.varName = queryName.varName />
</cfloop>
It's kind of hard to help without some code though.
没有一些代码,它很难帮助。
My question is: why are you storing your application variables in a database to begin with if you're just going to dump them back into the application scope?
我的问题是:如果您只是将它们转储回应用程序范围,为什么要将应用程序变量存储在数据库中?
#1
I do not know if the author was advocating that syntax or merely demonstrating that it works, as a point of interest.
我不知道作者是在提倡这种语法还是只是证明它有效,作为一个兴趣点。
Personally, I prefer array notation. I think it helps promote good scoping habits.
就个人而言,我更喜欢数组符号。我认为这有助于促进良好的范围生活习惯。
<!--- array notation --->
<cfset scope["staticName"& dynamicPortion] = "some value">
<!--- example 1 --->
<cfset variables["baseName"& x] = "oh brother">
<!--- example 2 --->
<cfset variables["baseName#x#"] = "oh brother">
#2
The answer to my question was to set dynamic variable names by quoting the names..
我的问题的答案是通过引用名称来设置动态变量名称。
<!--- Loop over the girls and alter the values. --->
<cfloop index="intGirl" from="1" to="3">
<!--- Randomly pick 1 (true) or 0 (false). --->
<cfif RandRange( 0, 1 )>
<!--- Set the dynamic variable naming used quoted evaluation. --->
<cfset "Girl#intGirl#" = "super sexy" />
</cfif>
</cfloop>
More here...
http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm
#3
use cfloop + cfset not cfoutput
使用cfloop + cfset而不是cfoutput
#4
If I'm reading your question correctly, you're saying that you're setting the application variables inside of a cfoutput tag?
如果我正确地阅读了您的问题,您是说您在cfoutput标签内设置了应用程序变量?
Are you using cfoutput like
你在使用cfoutput吗?
<cfoutput query="queryName">
<!--- Setting code in here --->
</cfoutput>
You should use cfloop rather than cfoutput
你应该使用cfloop而不是cfoutput
<cfloop query="queryName">
<cfset application.varName = queryName.varName />
</cfloop>
It's kind of hard to help without some code though.
没有一些代码,它很难帮助。
My question is: why are you storing your application variables in a database to begin with if you're just going to dump them back into the application scope?
我的问题是:如果您只是将它们转储回应用程序范围,为什么要将应用程序变量存储在数据库中?