Coldfusion this.mappings在cfc中不起作用 - >功能

如何获取我在application.cfc中定义的映射以在其他cfcs中的其他函数中工作? 即this.mappings [“plugins”]在任何页面上都可以正常工作但如果我尝试实例化一个包含调用this.mappings [“plugins”]的函数的cfc - 它就会失败。 谢谢 编辑: 我不确定 - 这就是我要做的事情: 在application.cfc中:
this.mappings["Plugins"] = 
getDirectoryFromPath(getCurrentTemplatePath())&'Assets/Plugins';
并在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>
    
已邀请:
我认为你称映射是错误的。在application.cfc中使用您的定义:
this.mappings["plugins"]
然后通过“插件”在其他代码中引用,所以:
var aName = new plugins.theCFC()
var aName = createObject("component","plugins.theCFC").init()
<cfinclude template="/plugins/aFile.cfm">
HTH,如果不在调用页面上发布您的代码。     
在CFC中,Application.cfc为1,“this”范围仅适用于该特定CFC。因此,当您处于CFM页面时,属于Application.cfc的管辖范围,那么“this”范围适用于Application.cfc,但是在CFC中,它适用于该特定CFC。 也就是说,为什么需要直接访问映射结构?如果要使用该映射来加载对象或包含文件,则可以执行
<cfinclude template="/plugins/path/to/myfile" />
<cfset obj = createobject("component","plugins.path.to.my.cfc") />
。 您需要直接访问结构的用例是什么?你想修改它吗? *编辑修复代码     
除非CF9中的内容发生了变化,否则代码中的第一个错误是在每个映射名称的开头定义映射键而没有斜杠“/”。 您将映射定义为
this.mappings["plugins"] =
它应该是
this.mappings["/plugins"] =
注意结构键名中的斜杠“/”。您必须以这种方式命名每个映射。 然后你会参考Sam Farmer在评论中提到的映射“   然后通过“插件”在其他代码中引用,所以:
var aName = new plugins.theCFC()
var aName = createObject("component","plugins.theCFC").init()
<cfinclude template="/plugins/aFile.cfm">
    

要回复问题请先登录注册