---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected]Eiither:
<cfset method = myObj[method] />
<cfset method() />In CFMX61, anyway (dunno about CFMX7: but no reason to believe it's changed), you might find you have problems with this if myObj[method] contains calls to other methods within the CFC that are private. Indeed, I've just tested this and I can't get it to work even if the embedded method call is public:
<!--- c.cfc --->
<cfcomponent>
<cffunction name="f">
<cfreturn p()>
</cffunction><cffunction name="p">
<cfreturn "private!">
</cffunction>
</cfcomponent><!--- caller.cfm --->
<cfset myObj = createObject("component", "c")>
<cfset method = "f">
<cfset method = myObj[method]>
<cfset method()>This errors saying it can't find variable p.
(I'm sure it was only PRIVATE methods that had this issue, last time I tested, but samesame with public ones in this test...?)
So, anyway, to get around this issue, I do this instead:
<!--- caller.cfm --->
<cfset o = createObject("component", "c")>
<cfset dynamic = "f">
<cfset o.temp = o[dynamic]>
<cfoutput>
#o.temp()#
</cfoutput>Much the same as your suggestion, except I poke the "non-dynamically-named method" back into the CFC.
Seems to work. A bit grim, but.
I can't bring myself to use <cfinvoke>, but I'd recommend it to others if asked.
--
Adam
Title: RE: [CFCDev] Calling a cfc method whose name is in a variable
Thanks everyone for these various approaches, I'll
check them out. Definitely some issues here I wasn't aware
of.
Adam, I hate to sound more OO-gnorant that I already
have, but why is cfinvoke so evil? Is it cfexecute-like
internally?
Dave Merrill
- RE: [CFCDev] Calling a cfc method whose name ... Dave Merrill
- RE: [CFCDev] Calling a cfc method whose ... Nando
- Re: [CFCDev] Calling a cfc method whose ... Sean Corfield
- Re: [CFCDev] Calling a cfc method wh... Jared Rypka-Hauer - CMG, LLC
- RE: [CFCDev] Calling a cfc method wh... Dave Merrill
- Re: [CFCDev] Calling a cfc metho... Paul Kenney
- RE: [CFCDev] Calling a cfc method whose ... Adam Cameron
- RE: [CFCDev] Calling a cfc method whose ... Keith Douglas
- Re: [CFCDev] Calling a cfc method wh... Sean Corfield
- RE: [CFCDev] Calling a cfc method whose ... Robertson-Ravo, Neil (RX)
- [CFCDev] controlling access to cfc f... Dave Merrill
