Application-Based Paths in ColdFusion
Posted on Friday, 14th March 2008 in Development by Simon
The THIS scope in the Application.cfc contains several built-in variables that allow you to set the properties of the application; the name, session management etc. With the release ColdFusion 8 comes the introduction of application-based pathing in the form of the THIS.mappings and THIS.customTagPaths variables.
The THIS.mappings variable can specify a structure that contains ColdFusion mappings. These settings take precedence over the mappings defined by ColdFusion Administrator Server Settings > Mappings page for the current application. Each structure element consists of the logical path as the key and the absolute path as the value. To use this variable, you must set the Enable Per Application Settings option on the ColdFusion Administrator Server Settings > Settings page.
For example:
<cfset THIS.mappings['/com'] = "C:\Inetpub\com" />This is syntactically equivalent to using the structInsert() function:
<cfset structInsert(THIS.mappings, '/com', 'C:\Inetpub\com') />The THIS.customTagPaths variable can specify a list that contains ColdFusion custom tag paths. These settings take precedence over the custom tag paths defined by the ColdFusion Administrator Server Settings > Mappings page for the current application. To use this variable, you must set the Enable Per Application Settings option on the ColdFusion Administrator Server Settings > Settings page.
For example:
<cfset THIS.customTagPaths = "C:\Inetpub\wwwroot\myAppOne\customTags" />Since we can specify a list, this is also valid:
<cfset THIS.customTagPaths = "C:\Inetpub\wwwroot\myAppOne\customTags,C:\Inetpub\wwwroot\myAppTwo\customTags" />Alternatively, we could represent the list as:
<cfset THIS.customTagPaths = "C:\Inetpub\wwwroot\myAppOne\customTags" /> <cfset THIS.customTagPaths = listAppend(THIS.customTagPaths, "C:\Inetpub\wwwroot\myAppTwo\customTags" />
For a long time, ColdFusion developers have needed the ability to define application-level settings actually in the application itself. These two new application-based pathing variables bring the ColdFusion developer a step closer to being able to produce out-of-the-box applications that can install in shared environments with little fuss and, more importantly, without the need to access the ColdFusion Adminsitrator to create the necessary mappings and custom tag paths.
I have added an example for per app settings on my blog…
http://coldfusion8.blogspot.com/2008/03/per-app-settings-example.html
I’m having an issue with my application randomly losing access to the location of my custom tags. Specifically I am getting the following error:
“Cannot find CFML template for foo”
I’m dynamically setting my application root, and deriving my custom tag path from that:
<cfset this.root = getDirectoryFromPath(getCurrentTemplatePath()) />
<cfset this.customtagpaths = this.root & “extensionscustom_tags” />
Would there be any problems with using the above to derive the location of these tags?