Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

List of functions in CFC

New Here ,
May 13, 2010 May 13, 2010

Hi,

I need to get a list of functions inside a CFC and then do 'something with that list'. I know I can dump the visual output after I instantiate the object, but I can't seem to access the 'methods' key as a structure/array etc. Anyone know how to interpret the contents of the object (like looping through it for example)?

Cheers
John

429
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2010 May 13, 2010

There are a couple of approaches.  All the methods within a CFC are in its THIS (public, remote, package) or VARIABLES (private) scope, so one could iterate over those and check each key as to whether it passes isCustomFunction() (http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_in-k_10.html).

But better would be to use getMetaData() (http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_50.html) on an instance of the CFC, or - on CF9 -  getComponentMetaData() (http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7dd9.html), if you don't want to first instantiate the CFC.

--
Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 13, 2010 May 13, 2010

Perfect!

I am going to use the getMetaData(). Out of interest though how would I iterate over the methods in THIS? I cant get at the methods [struct?] but I can obviously see it in a dump...

Thanks

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2010 May 13, 2010
LATEST

From within the CFC code:

<cfloop item="sVariable" collection="#this#">

     <cfif isCustomFunction(this[sVariable])>

From the calling code:

<cfloop item="sVariable" collection="#objName#">

      <cfif isCustomFunction(objName[sVariable])>

Have never had call to do the latter, but it should work (?)

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources