如何在不使用Evaluate()的情况下动态调用作为实例化cfc一部分的函数?

时间:2020-03-05 18:59:10  来源:igfitidea点击:

例如,我希望能够以编程方式命中如下代码行,而无需使用Evaluate()即可动态分配函数名称。下面的代码当然不起作用,但是代表了我想做的事情。

application.obj[funcName](argumentCollection=params)

我可以找到动态调用函数的唯一方法是使用cfinvoke,但据我所知,它可以即时实例化相关的cfc / function,而不能使用先前实例化的cfc。

谢谢

解决方案

回答

根据文档,我们可以执行以下操作:

<!--- Create the component instance. --->
<cfobject component="tellTime2" name="tellTimeObj">
<!--- Invoke the methods. --->
<cfinvoke component="#tellTimeObj#" method="getLocalTime" returnvariable="localTime">
<cfinvoke component="#tellTimeObj#" method="getUTCTime" returnvariable="UTCTime">

我们应该能够简单地使用method ="#myMethod#"进行调用,以动态调用特定的函数。

回答

我们可以使用cfinvoke。我们不必指定组件。

<cfinvoke method="application.#funcName#" argumentCollection="#params#">