gpt4 book ai didi

coldfusion - 如何最好地创建和存储 APPLICATION 变量?

转载 作者:行者123 更新时间:2023-12-04 18:13:28 24 4
gpt4 key购买 nike

我正在使用 ColdFusion 9.0.1

我正在接管一个站点,而我之前的那个人创建了大约 100 个变量并将它们放入 APPLICATION 范围内。我相信他的 100 个变量会随着每次页面加载而不断被覆盖。

基本上,他在 Application.cfc 中有这个:

APPLICTION.VariableOne = "SomeStringOne";
APPLICTION.VariableTwo = "SomeStringTwo";
APPLICTION.VariableThree = "SomeStringThree";

我的计划是保持简单但可读性强,是在应用程序范围内测试特定结构。如果不存在,请创建结构和变量:
if (not isDefined("APPLICTION.AppInfo") or not isStruct(APPLICTION.AppInfo)) {
APPLICTION.AppInfo = structNew();
APPLICTION.AppInfo.VariableOne = "SomeStringOne";
APPLICTION.AppInfo.VariableTwo = "SomeStringTwo";
APPLICTION.AppInfo.VariableThree = "SomeStringThree";
}

当然,一旦站点上线并且我们完成了所有应用程序变量的创建,我会将其移至 onApplicationStart() 方法中。

我想要的解决方案必须更多地关注“可读性”,而不是“效率”。一些非 CFers,但非常有经验的编码人员将使用它,并且需要快速“获取”它。

我的计划是否有漏洞或效率太低?

是否有更易读的方式来创建和管理应用程序变量?

最佳答案

为什么不立即将定义移到 onApplicationStart() 中?如果您需要在开发过程中重置它们,您总是可以传入一个 URL 变量来标记它以进行重置,如下所示:

<!--- in Application.cfc --->

<cffunction name="onRequestStart">
<cfif IsDefined("url.resetApp")>
<cfset ApplicationStop()>
<cfabort><!--- or, if you like, <cflocation url="index.cfm"> --->
</cfif>
</cffunction>

关于coldfusion - 如何最好地创建和存储 APPLICATION 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8301984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com