Jak mogę dołączyć odwzorowania do Application.cfc z zewnętrznego pliku właściwości?
Mam problem z ustawieniem mapowań w Application.cfc. Mamy diverent Server (dev, QS, prod) Każdy z trochę innymi Pathes. Chcę ustawić specyficzne dla serwerów patche i zmienne za pomocą pliku konfiguracyjnego. Na ApplicationStart czytasz plik ini i konfigurujesz system.http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo To działa dobrze.
Normalnie ustawiasz mapowania w Applcation.cfc tak:
<!--- in Application.cfc --->
<cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components">
Gdzieś w normalnym pliku cfm inicjuję test cfc nazwany przez:
<cfset t = createObject("component", "components.test")>
Chcę ustawić mapowania tylko raz naonApplicationsStart
<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>
Ale to nie działa, ponieważ this.mappings jest puste i następne żądanie. :(
Umieszczenie tego w OnRequestStart
<!--- 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>
Dostaję błąd, że nie można znaleźć komponentu. To jest dziwne.
Umieszczenie struktury w zakresie aplikacji
<cfloop index="key" list="#sections.mappings#">
<cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
</cfloop>
Jak zadzwonić do mojego komponentu?
<cfset t = createObject("component", "application.components.test")>
Nie działa
Więc mam 3 cele.
czytanie wszystkich pathes i mapowań z pliku iniczytanie ich raz na ApplicationStartłatwe korzystanie z kodu źródłowego.