Search code examples
functioncoldfusioncfcmappings

Coldfusion this.mappings does not work in a cfc -> function


How do I get the mappings I have defined in application.cfc to work in other functions in other cfcs?

i.e. this.mappings["plugins"] works just fine on any page but if I try to instantiate a cfc containing a function that calls this.mappings["plugins"] - it fails.

thanks

EDIT: I'm not sure - here's what I am trying to do: In application.cfc:

this.mappings["Plugins"] = \
getDirectoryFromPath(getCurrentTemplatePath())&'Assets/Plugins';

and in stock.cfc:

<cfcomponent output="yes" > 
<cffunction name="showIndecies" access="public" output="yes" returntype="string">
<cfscript>
j = 1; 
variables.indeciesArray = ArrayNew(1); 
variables.indeciesFile = \
application.mappings["Plugins"]&'/StockMarketData/Data/indecies.csv'; 
</cfscript>

Solution

  • I think you are calling the mapping wrong. Using your definition in application.cfc:

    this.mappings["plugins"]
    

    Would then be referenced in other code by "plugins" so:

    var aName = new plugins.theCFC()
    var aName = createObject("component","plugins.theCFC").init()
    <cfinclude template="/plugins/aFile.cfm">
    

    HTH, if not post your code on the calling page.