Como posso incluir mapeamentos no Application.cfc a partir do arquivo de propriedades externas?
Eu tenho problemas com a definição de mapeamentos em Application.cfc Temos Servidor divergente (dev, QS, prod) Cada um com um caminho diferente. Eu quero definir pathes específicos do servidor e variáveis via arquivo de configuração. No ApplicationStart, você lê o arquivo ini e configura seu sistema.http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo Isso funciona bem.
Normalmente você define os mapeamentos em Applcation.cfc assim:
<code><!--- in Application.cfc ---> <cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components"> </code>
Em algum lugar em um arquivo cfm normal, instati um teste chamado cfc via:
<code><cfset t = createObject("component", "components.test")> </code>
Eu quero definir os mapeamentos apenas uma vez emonApplicationsStart
<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>
Mas isso não funciona porque this.mappings está vazio e próximo pedido. :(
Colocando isso em 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>
Eu recebo um erro que o componente não pode ser encontrado. Isto é estranho.
Colocando a estrutura no escopo do aplicativo
<code> <cfloop index="key" list="#sections.mappings#"> <cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)> </cfloop> </code>
Como chamar meu componente?
<code><cfset t = createObject("component", "application.components.test")> </code>
Não funciona.
Então eu tenho 3 alvos.
lendo todos os pathes e mapeamentos do arquivo inilê-los uma vez no ApplicationStartuso fácil no código fonte.