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



我正试图获得CFC链接,但我得到一个错误:

这是我的配置在我的应用程序。cfc

<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. 

我把Application Scope删除了,看起来一切正常,但是我不知道这里出了什么问题

Application.cfcpathApplication.tools都是字符串,所以只能作为字符串使用;而语句中的Application.cfcpath.tools:

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

是一个变量引用。你不能让一个字符串包含一个变量引用,并希望ColdFusion能神奇地将两者等同起来。

从你的问题中不清楚你是否试图用你的语句创建一个对象,或者只是引用一个现有的对象。我怀疑是前者。在这种情况下,你想要这样的东西,我认为:

tools = createObject(Application.tools);

最新更新