Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a function dynamically that is part of an instantiated cfc, without using Evaluate()?

Tags:

coldfusion

cfc

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

like image 406
Dan Roberts Avatar asked Sep 17 '08 15:09

Dan Roberts


1 Answers

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.

like image 64
Ben Doom Avatar answered Sep 25 '22 06:09

Ben Doom