1

我四处闲逛,并认为将我的应用程序变量移动到可以在ApplicationStart 上加载的表中会很好。

我的意图是允许 ANT 推出应用程序,并更改数据库中的一些设置和众所周知的 presto..

在我的测试代码中,application.cfc 有一个简单的查询来调用所有变量名,然后有一个 cfloop 来将应用程序范围内的每个变量设置为 application.varname。

ApplicationStart 上没有报告错误..但是尝试引用变量会给出未定义的类型错误。

我的蜘蛛感官告诉我这是一件小而明显的事情……有什么想法吗?

谢谢!!

更新1:似乎我正在查看的是设置动态变量名称,而它们是应用程序变量这一事实似乎没有太大影响。

http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm

4

4 回答 4

6

我不知道作者是在提倡这种语法还是仅仅证明它有效,作为一个兴趣点。

就个人而言,我更喜欢数组表示法。我认为这有助于促进良好的范围界定习惯。

<!--- array notation --->
<cfset scope["staticName"& dynamicPortion] = "some value"> 

<!--- example 1  --->
<cfset variables["baseName"& x] = "oh brother">
<!--- example 2  --->
<cfset variables["baseName#x#"] = "oh brother">
于 2009-05-08T22:39:07.377 回答
4

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

于 2009-05-08T19:37:23.507 回答
3

使用 cfloop + cfset 而不是 cfoutput

于 2009-05-08T18:58:55.657 回答
2

如果我正确阅读了您的问题,您是说您在 cfoutput 标记内设置应用程序变量?

您是否使用 cfoutput 之类的

<cfoutput query="queryName">
  <!--- Setting code in here --->
</cfoutput>

您应该使用 cfloop 而不是 cfoutput

<cfloop query="queryName">
  <cfset application.varName = queryName.varName />
</cfloop>

但是,如果没有一些代码,很难提供帮助。

我的问题是:如果您只是要将应用程序变量转储回应用程序范围,为什么要将它们存储在数据库中?

于 2009-05-08T19:11:16.783 回答