应用范围的问题获取CFC的范围

时间:2014-06-26 07:44:18

标签: coldfusion

我正在尝试连接CFC,但我收到错误:

这是我的Application.cfc中的Configration

<cfset Application.relativePath = "/">
  <cfset Application.componentsPath = Replace(Application.relativePath,"/","",'All')>
  <cfset Application.cfcpath = Application.componentsPath & "com">
  <cfset Application.tools = '#Application.cfcpath#.tools'>

现在,当我从我的页面访问cfc时,这样:

<cfset result = Application.cfcpath.tools.saveDrivers(form)>

我收到错误:

Element CFCPATH.TOOLS is undefined in a Java object of type class [Ljava.lang.String; referenced as '' 

如果我尝试

<cfset result = Application.tools.saveDrivers(form)>

我收到错误:

The saveDrivers method was not found.
Either there are no methods with the specified method name and argument types or the saveDrivers method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity. 

我抛弃了应用范围,一切似乎都没问题,但我不确定这里有什么问题

1 个答案:

答案 0 :(得分:9)

Application.cfcpathApplication.tools都只是字符串,因此只能用作字符串;而声明中的Application.cfcpath.tools

<cfset result = Application.cfcpath.tools.saveDrivers(form)>

是变量引用。你不能拥有一个包含变量引用的字符串,并希望以某种方式将ColdFusion神奇地等同于两者。

从您的问题中不清楚您是在尝试使用语句创建对象,还是只是引用现有对象。我怀疑它是前者。在这种情况下,你想要这种东西,我想:

tools = createObject(Application.tools);