coldfusion - 我可以在 onApplicationStart() 内部设置 this.customTagPaths 吗?

标签 coldfusion

我正在尝试根据配置页面上设置的值动态设置 application.cfc 上的 this.customTagPaths 变量。这是因为我的开发中的 customTagPaths 与实时站点上的不同,并且我不想每次部署到实时站点时都必须更改该值。我也无法通过实时站点上的 CF 管理设置自定义标记路径,因为我无法控制实时 CF 服务器。我发现如果我在 onApplicationStart() 内部设置该值,则无法识别该值:

<cffunction name="OnApplicationStart"...

    <!---application.customTagPaths is set on the config page. On dev, this value is "C:/Inetpub/wwwroot/mySite/components/"--->
    <cfinclude template = config/appsettings.cfm">
    <cfset this.customTagPaths = application.customTagPaths>

使用上面的代码,当我尝试在 cfm 页面上实例化对象时,出现“找不到组件”错误:

<cfset session.user = createObject("component", "user").init()>

所以我想我的问题的答案是“不”。我想原因是 onApplicationStart() 内部的“this”范围是函数的本地范围,与用于设置 this.name 和 this.applicationTimeout 等的“this”范围不同。我可以在 application.cfc 页面顶部执行 appsettings.cfm 的 cfinclude,并在其下方设置 this.customTagPaths:

<cfcomponent>
     <cfinclude template="config/appsettings.cfm">
     <cfset this.Name="myApp">
     <cfset this.customTagPaths = application.customTagPaths>
     ...

这可行,但是这是理想的吗?

最佳答案

正如您所发现的,您最初的问题的答案是否定的。
您后一个问题的答案是肯定的,这正是您应该这样做的。除非您不会使用应用程序范围引用。这些应用程序设置并未真正存储在应用程序范围中。

对于可能偶然发现此问题的其他人,为了在 Application.cfc 文件中使用每个应用程序设置,您必须首先在 ColdFusion 管理员的“设置”页面上启用每个应用程序设置。然后,您可以在 Application.cfc 文件中设置映射或自定义标记路径,如下所述。

Documentation reference for specifying settings per application

Custom Tags in per-application settings override those defined in the ColdFusion Administrator. For example, if you have two custom tags of the same name and they are in different locations in the Administrator and per-application settings, the one in the per-application settings is taken first.

Note: Per-application settings are supported in applications that use an Application.cfc file only, not in applications that use an Application.cfm file. The per-application settings do not work if you have disabled application variables in the Memory Variables page of the Administrator.

Set the custom tag paths per application

  1. Check the Enable Per App Settings option on the Settings page of the ColdFusion Administrator.
  2. Include code like the following in your Application.cfc file:

<cfset customtagpaths = "c:\mapped1,c:\mapped2">
<cfset customtagpaths = ListAppend(customtagpaths,"c:\mapped3")>
<cfset This.customtagpaths = customtagpaths>

关于coldfusion - 我可以在 onApplicationStart() 内部设置 this.customTagPaths 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29497856/

相关文章:

sql-server - sql语句中的Cfloop?

javascript - 在 document.GetElementByID ('input' ).value = 'data[0]' 期间 DecodeForHTML,使用动态数组数据

ms-access - Coldfusion 输入格式和时间

coldfusion - 显示图片调用数据库中图片的名称

coldfusion - 在 ColdFusion 中,从 http 切换到 https 后我需要重新建立 session token 吗?

jquery - 如何通过ajax提交一千个选中的复选框?

Coldfusion 重定向状态码为 410 的页面

excel - 导出到 Excel 无法正确显示数字

jquery - 如何在 jQuery 中输出 JSON 列

coldfusion - 请求已超过允许的时间限制标记 : cfoutput