We often create a folder in our application root that contains all components used for the application. We then create a mapping to that folder so that we can invoke components from anywhere within the application.
Not happy with this approach (prefer an application that just works when it moves server), I just wrote this little function that you can add to application.cfm that will let you invoke a component method from anywhere in the application. Has this been done before? Any thoughts? Anyways, here it is: <cffunction name="GetComponent" returntype="any" hint="Returns the results of a given CFC method call"> <cfargument name="name" type="string" required="true" hint="Name of the component" /> <cfargument name="method" type="string" required="false" default="init" hint="The name of the component method to invoke"> <cfargument name="args" type="struct" required="false" default= "#StructNew()#" hint="Structure containing invoke method arguments"> <cfargument name="componentsFolder" type="string" required="false" default="_components" hint="Folder in root directory in which your components are stored"> <cfinvoke component="#arguments.componentsFolder#.#arguments.name#" method="#arguments.method#" returnvariable="returnValue"> <cfloop list="#StructKeyList(arguments.args)#" index="thisArg"> <cfinvokeargument name="#thisArg#" value="#arguments.args[thisArg]#"> </cfloop> </cfinvoke> <cfreturn returnValue> </cffunction> Example call: <cfset o_myObject = GetComponent("myCFC")> This example assumes the component, myCFC, has an init method which takes no arguments. -- Blog it up: http://blog.dominicwatson.co.uk ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Create robust enterprise, web RIAs. Upgrade to ColdFusion 8 and integrate with Adobe Flex http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287031 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4