Created
June 1, 2012 17:38
-
-
Save rip747/2853902 to your computer and use it in GitHub Desktop.
implementing a CFWheels service layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- 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