我试图让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'>
Run Code Online (Sandbox Code Playgroud)
现在,当我从我的页面访问cfc时,如下所示:
<cfset result = Application.cfcpath.tools.saveDrivers(form)>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Element CFCPATH.TOOLS is undefined in a Java object of type class [Ljava.lang.String; referenced as ''
Run Code Online (Sandbox Code Playgroud)
如果我试试
<cfset result = Application.tools.saveDrivers(form)>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
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.
Run Code Online (Sandbox Code Playgroud)
我抛弃了应用范围,一切似乎都没问题,但我不确定这里有什么问题
这两个Application.cfcpath和Application.tools仅仅是字符串,所以只能作为字符串; 而Application.cfcpath.tools在声明中:
<cfset result = Application.cfcpath.tools.saveDrivers(form)>
Run Code Online (Sandbox Code Playgroud)
是一个变量引用.你不能拥有一个包含变量引用的字符串,并希望ColdFusion能以某种方式将两者完全等同起来.
从您的问题中不清楚您是在尝试使用语句创建对象,还是只是引用现有对象.我怀疑它是前者.在这种情况下,你想要这种东西,我想:
tools = createObject(Application.tools);
Run Code Online (Sandbox Code Playgroud)