小编ino*_*nog的帖子

如何从外部属性文件中将映射包含到Application.cfc中?

我在Application.cfc中设置映射时遇到问题我们有一个exrent服务器(dev,QS,prod)每个都有一些不同的Pathes.我想通过配置文件设置服务器特定的pathes和变量.在ApplicationStart上,您可以阅读ini文件并设置系统. http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo 这很好用.

Normaly你在Applcation.cfc中设置映射如下:

<!--- in Application.cfc --->
<cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components">
Run Code Online (Sandbox Code Playgroud)

在普通的cfm文件中的某处,我通过以下方式实例化名为test的cfc:

<cfset t = createObject("component", "components.test")>
Run Code Online (Sandbox Code Playgroud)

我想在onApplicationsStart上只设置一次映射

<cffunction
    name="OnApplicationStart"
    access="public"
    returntype="boolean"
    output="false"
    hint="Fires when the application is first created.">

    <!---create structure to hold configuration settings--->
    <cfset ini = structNew()>
    <cfset ini.iniFile = expandPath("./ApplicationProperties.ini")>
    <cfset application.ini = ini>

    <!--- read ini file --->
    <cfset sections = getProfileSections(application.ini.iniFile)>

    <cfloop index="key" list="#sections.mappings#">
       <cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为this.mappings为空并且下一个请求.:(

把它放到OnRequestStart上

<!--- read ini file --->
    <cfset sections = …
Run Code Online (Sandbox Code Playgroud)

mapping coldfusion properties application.cfc

5
推荐指数
1
解决办法
1808
查看次数

标签 统计

application.cfc ×1

coldfusion ×1

mapping ×1

properties ×1