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

Coldfusion 如何使用cfscript从另一个cfm页面调用cfc中的cffunction?,coldfusion,cfc,Coldfusion,Cfc,我有一个test.cfm页面,希望使用该页面(test.cfm)中的而不是 <cfinvoke component = "#cfcPath#" method = "errorEmail" returnVariable = "myReturn" description = "get list of projman"> </cfinvoke> 我试过: <cfscript> errorEmail(cfcPath); </cfscrip

我有一个
test.cfm
页面,希望使用该页面(test.cfm)中的
而不是

<cfinvoke component = "#cfcPath#" method = "errorEmail" returnVariable = "myReturn" 
    description = "get list of projman">
</cfinvoke> 

我试过:

<cfscript>
   errorEmail(cfcPath);
</cfscript>

错误电子邮件(cfcPath);

我一直都这样做

1) 创建对象:

<cfscript>
    // CREATE OBJECT 
    TheCFC = createObject("component", "thecfc");
</cfscript>

//创建对象
TheCFC=createObject(“组件”、“TheCFC”);
2) 调用函数:

<cfscript>
    // CALL THE FUNCTION
    SomeVariable = TheCFC .theFunction();
</cfscript>

//调用函数
SomeVariable=TheCFC.theFunction();
你的版本应该是这样的

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

//创建对象
TheObject=createObject(“组件”、“路径”);
//调用函数
myReturn=TheObject.errorEmail();

不使用cfinvoke标记调用
errorEmail
的原因是什么?这就是我在cfcs中测试功能的方法。我创建一个test.cfm页面并调用我正在测试的cfc中的函数。然后我通常在test.cfm中进行cfdumps,以确保函数正常工作;是的,你能做到。通常,我不会。我在页面顶部创建对象,并可能在整个页面中多次引用它。好主意!谢谢各位,这将帮助我更快地测试我的功能!还有,@Eric我不知道你可以像jQuery一样连锁,谢谢。我同意@Evik的说法。如果要在模板中多次重用对象,请将其存储在变量中并重新使用。但是,如果您仅为一个目的创建对象,则首选链接方法调用。如果您使用CF9+,也可以转到
myReturn=new path.to.cfc().method()