tags:

views:

411

answers:

2

For example I want to be able to programatically hit a line of code like the following where the function name is dynamically assigned without using Evaluate(). The code below of course doesn't work but represents what I would like to do.

application.obj[funcName](argumentCollection=params)

The only way I can find to call a function dynamically is by using cfinvoke, but as far as I can tell that instantiates the related cfc/function on the fly and can't use a previously instantiated cfc.

Thanks

+3  A: 

According to the docs, you can do something like this:

<!--- 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">

You should be able to simply call it with method="#myMethod#" to dynamically call a particular function.

Ben Doom
I tried various combinations for cfinvoke but somehow overlooked this. Thanks
Dan Roberts
+2  A: 

You can use cfinvoke. You don't have to specify a component.

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