Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I include mappings into Application.cfc from external property file?
    text
    copied!<p>I have trouble with setting mappings in Application.cfc We have diverent Server (dev,QS,prod) Each with a little different Pathes. I want to set serverspecific pathes and variables via configuration file. On ApplicationStart you read the ini file and setup your system. <a href="http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo" rel="nofollow">http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo</a> This works fine. </p> <p>Normaly you set mappings in Applcation.cfc like this:</p> <pre><code>&lt;!--- in Application.cfc ---&gt; &lt;cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components"&gt; </code></pre> <p>Somewhere in a normal cfm File I instatiate a cfc named test via:</p> <pre><code>&lt;cfset t = createObject("component", "components.test")&gt; </code></pre> <p>I want to set the mappings only once at <strong>onApplicationsStart</strong></p> <pre><code>&lt;cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false" hint="Fires when the application is first created."&gt; &lt;!---create structure to hold configuration settings---&gt; &lt;cfset ini = structNew()&gt; &lt;cfset ini.iniFile = expandPath("./ApplicationProperties.ini")&gt; &lt;cfset application.ini = ini&gt; &lt;!--- read ini file ---&gt; &lt;cfset sections = getProfileSections(application.ini.iniFile)&gt; &lt;cfloop index="key" list="#sections.mappings#"&gt; &lt;cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)&gt; &lt;/cfloop&gt; </code></pre> <p>But this don't work because this.mappings is empty and next request. :(</p> <p>Putting this to OnRequestStart</p> <pre><code>&lt;!--- read ini file ---&gt; &lt;cfset sections = getProfileSections(application.ini.iniFile)&gt; &lt;cfloop index="key" list="#sections.mappings#"&gt; &lt;cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)&gt; &lt;/cfloop&gt; </code></pre> <p>I get an error that the component can't be found. This is strange. </p> <p>Putting the struct into Application scope </p> <pre><code> &lt;cfloop index="key" list="#sections.mappings#"&gt; &lt;cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)&gt; &lt;/cfloop&gt; </code></pre> <p>How to call my Component?</p> <pre><code>&lt;cfset t = createObject("component", "application.components.test")&gt; </code></pre> <p>Doesn't work.</p> <p>So I have 3 targets.</p> <ol> <li>reading all pathes and mappings from ini file</li> <li>reading them once at ApplicationStart</li> <li>easy usage in sourcecode.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload