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:
<code><!--- in Application.cfc ---> <cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components"> </code>
Gdzieś w normalnym pliku cfm inicjuję test cfc nazwany przez:
<code><cfset t = createObject("component", "components.test")> </code>
Chcę ustawić mapowania tylko raz naonApplicationsStart
<code><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> </code>
Ale to nie działa, ponieważ this.mappings jest puste i następne żądanie. :(
Umieszczenie tego w OnRequestStart
<code><!--- 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> </code>
Dostaję błąd, że nie można znaleźć komponentu. To jest dziwne.
Umieszczenie struktury w zakresie aplikacji
<code> <cfloop index="key" list="#sections.mappings#"> <cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)> </cfloop> </code>
Jak zadzwonić do mojego komponentu?
<code><cfset t = createObject("component", "application.components.test")> </code>
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.