Shaun Mccran

My digital playground

07
J
U
L
2008

Init method for coldfusion cfc's

I'm lucky enough to be working in an environment that is small enough to allow me access to our whole suite of coldfusion cfc's. So i generally know pretty much what they all do, but what if your interrogating unknown cfc's?

Well you can use the init() method.

'Best Practice' would dictate that there is an init() method in every cfc. In fact its something that I've only recently starting doing out of habit, it used to be more of a 'as and when you need it' kind of thing. But with an ever increasing function library, I've found it essential.

The idea is that the 'this' scope is specific to the cfc instance created. So doing this:

view plain print about
1<cffunction name="init" hint="Displays schema of this cfc">
2
3        <cfreturn this>
4 </cffunction>

Will return all of the functions and definitions for the current cfc. Invoke it however you will:

view plain print about
1Purchase Orders init:
2<cfinvoke component="purchaseOrder" method="init" returnvariable="test">
3
4<cfdump var="#test#">

And you'll see a schema for the whole cfc!

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top