Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Mappings can't be set in onApplicationStart(), they must be set in the pseudo constructor of Application.cfc, and they must be set on every request. </p> <p>It's also important to note that the application scope is not available at this point, therefore if you need to cache anything you'll need to use the server scope. You can cache your mapping struct to the server scope and just set it into this.mappings each request.</p> <pre><code>&lt;cfcomponent&gt; &lt;cfset this.name = "myapp" /&gt; &lt;!--- not cached so create mappings ---&gt; &lt;cfif NOT structKeyExists(server, "#this.name#_mappings")&gt; &lt;cfset iniFile = getDirectoryFromPath(getCurrentTemplatePath()) &amp; "/ApplicationProperties.ini" /&gt; &lt;cfset sections = getProfileSections(iniFile) /&gt; &lt;cfset mappings = structnew() /&gt; &lt;cfloop index="key" list="#sections.mappings#"&gt; &lt;cfset mappings[key] = getProfileString(iniFile, "mappings", key)&gt; &lt;/cfloop&gt; &lt;cfset server["#this.name#_mappings"] = mappings /&gt; &lt;/cfif&gt; &lt;!--- assign mappings from cached struct in server scope ---&gt; &lt;cfset this.mappings = server["#this.name#_mappings"] /&gt; &lt;cffunction name="onApplicationStart"&gt; &lt;!--- other stuff here ---&gt; &lt;/cffunction&gt; &lt;/cfcomponent&gt; </code></pre> <p>If you intend to keep you ini file in the webroot, you should make it a .cfm template and start it with a &lt;cfabort>. It will work just the same but will not be readable</p> <p><em>ApplicationProperties.ini.cfm</em></p> <pre><code>&lt;cfabort&gt; [mappings] /foo=c:/bar/foo </code></pre>
 

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