---------------------------------------------------------- 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]-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Dave Merrill
Sent: Tuesday, March 15, 2005 11:17 PM
To: [email protected]
Subject: RE: [CFCDev] Calling a cfc method whose name is in a variableThanks 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---------------------------------------------------------- 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
Dave,
I've
used cfinvoke in over 30 productions apps where i needed to call both
components and methods dynamically, and i've never had a problem with it -
and that particular chunk of code has been hit millions of times ...
seems to work very efficiently as well.
- RE: [CFCDev] Calling a cfc method whose name ... 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 ... Keith Douglas
- Re: [CFCDev] Calling a cfc method wh... Sean Corfield
- RE: [CFCDev] Calling a cfc method whose ... Adam Cameron
- RE: [CFCDev] Calling a cfc method whose ... Robertson-Ravo, Neil (RX)
- [CFCDev] controlling access to cfc f... Dave Merrill
- Re: [CFCDev] controlling access ... Peter J. Farrell
