你如何使用cfscript从另一个cfm页面调用cfc中的cffunction?

isu*_*use 11 coldfusion cfc

我有一个test.cfm页面,并希望 从该页面(test.cfm)调用一个<cffunction>名为errorEmailusing 的cfc <cfscript>而不是

<cfinvoke component = "#cfcPath#" method = "errorEmail" returnVariable = "myReturn" 
    description = "get list of projman">
</cfinvoke> 
Run Code Online (Sandbox Code Playgroud)

我试过了:

<cfscript>
   errorEmail(cfcPath);
</cfscript>
Run Code Online (Sandbox Code Playgroud)

Evi*_*mes 13

我一直这样做.

1)创建对象:

<cfscript>
    // CREATE OBJECT 
    TheCFC = createObject("component", "thecfc");
</cfscript>
Run Code Online (Sandbox Code Playgroud)

2)调用函数:

<cfscript>
    // CALL THE FUNCTION
    SomeVariable = TheCFC .theFunction();
</cfscript>
Run Code Online (Sandbox Code Playgroud)

你的版本看起来像这样

<cfscript>
    // CREATE OBJECT 
    TheObject = createObject("component", "cfcPath");
    // CALL THE FUNCTION
    myReturn = TheObject.errorEmail();
</cfscript>
Run Code Online (Sandbox Code Playgroud)

  • 您可以通过链接调用来缩短它:createObject("component","cfcPath").errorEmail(); (4认同)
  • 是的,你可以这样做.通常情况下,我没有.我在页面顶部创建对象,并可能在整个页面中多次引用它.好主意虽然! (2认同)