Ask a Jedi: Getting CFC method names

This post is more than 2 years old.

Justice (which sounds like a superhero name) asks:

Is there a way to parse a list of methods from a .CFC into an array using introspection? I am creating a simple ajax form to do testing of .cfc methods, and I would like to auto-populate a drop down of available methods after the user enters a component name. I know I can <cfobject> the component and then dump it, but how would I reference the methods as variable's?

First off, to get the methods from a CFC instance you would use the getMetaData function like so:

<cfset messageCFC = createObject("component", "forums.cfcs.message")> <cfset methods = getMetaData(messageCFC).functions> <cfdump var="#methods#">

The getMetaData function will return a lot of information about the CFC, but note that I am just using the functions key. How could you then invoke a method dynamically? The cfinvoke tag can be passed a dynamic name:

<cfinvoke component="messageCFC" method="#someMethod#">

It would probably be a bit difficult to handle the arguments like this in a truly 100% dynamic fashion, but this should give you the basics for what you want to do.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA