Skip to content

Instantly share code, notes, and snippets.

@rip747
Created June 1, 2012 17:38
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rip747/2853902 to your computer and use it in GitHub Desktop.
implementing a CFWheels service layer
<!--- add the following to the events/onapplicationstart.cfm --->
<cffunction name="initServices" returntype="void" hint="I initialize the services objects for this app">
<cfset var loc = {}>
<cfset application.$_ServiceObjects = {}>
<cfdirectory action="list" directory="#expandPath('services')#" name="loc.services"/>
<cfloop query="loc.services">
<cfset application.$_ServiceObjects[ListFirst(name, '.')] = createObject("component", "services.#ListFirst(name, '.')#").init()>
</cfloop>
</cffunction>
<cfset initServices()>
<!--- add the following to the events/functions.cfm --->
<cffunction name="service" returntype="any" hint="I am the method used to access any service layer object from within any controller">
<cfargument name="service" type="string" required="true" />
<cfset var retval = "" />
<cfif structkeyExists(application.$_ServiceObjects,arguments.service)>
<cfset retval = application.$_ServiceObjects[arguments.service] />
</cfif>
<cfreturn retval />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment