Here is what I do.

1. d:\wwwroot\components setup a mapping to this directory called
components or something.

2. each website has it's own folder for components under this directory.
For example.
d:\wwwroot\components\myweb1

3. In d:\wwwroot\components there is also a file that is used by all
applications for my udfs. cfcremotedocumenter.cfm is also in this directory.

d:\wwwroot\components\udfs.cfc

4. Inside that folder I have one folder and two files. The first file is
a config.xml file. The second is a factory.cfc.

5. The config.xml file contains variables that you would normally setup
in your application.cfm file.

<?xml version="1.0" encoding="UTF-8"?>
<config>
<dsn>yourwebsitedsn</dsn>
<mapping>/yourwebsitemapping/</mapping>
<baseURL>http://www.mywebsite.com/</baseURL>
<mailServer>mail.myserver.com</mailServer>
</config>

6. The factory.cfc contains the following.

<cfcomponent extends="components.udfs">
<!---
**
* Includes file that documents this component.
*
**
--->
<cfset instance.documentedAccessLevels='private,package,public,remote'>
<cfinclude template="../cfcremotedocumenter.cfm">
<!---
**
* Initializes local variables used within this component.
**
--->
<cfset init()>

<cfdirectory action="">
directory="#getDirectoryFromPath(getCurrentTemplatePath())&'function_includes\'#"

filter="_*_functions.cfm"
name="qry_getFunctionIncludes">


<cffunction name="init" access="public" returntype="struct" output="false"
hint="Global Variables used within component.">

<cfset var initReturn=structNew()>
<cfset var objXML=''>
<cfset var idx=1>

<cffile action="" charset="utf-8"
file="#replaceNoCase(getCurrentTemplatePath(),
listLast(getCurrentTemplatePath(), '\'), 'config.xml')#"
variable="objXML">

<cfset objXML=xmlParse(objXML)>
<cfset objXML=xmlSearch(objXML, '/config/')>

<cfloop from="1" to="#arrayLen(objXML[1].xmlChildren)#" index="idx">
<cfset
initReturn[objXML[1].xmlChildren[idx].xmlName]=objXML[1].xmlChildren[idx].xmlText>
</cfloop>

<cfreturn initReturn>
</cffunction>

<cffunction name="getVars" access="public" returntype="any" output="false"
hint="Returns the global vars initialized in the init() function.">

<cfset var getVarsReturn=init()>

<cfreturn getVarsReturn>
</cffunction>

<cfoutput query="qry_getFunctionIncludes">
<cfinclude template="function_includes/#name#">
</cfoutput>

</cfcomponent>

7. There is a function_includes for each application under
d:\wwwroot\components\myweb1\function_includes

8. Inside that folder I have all my functions. I split the files up into
logical function sets and make them a cfml page that is included by
factory.cfc. For example:

_calendar_functions.cfm
_document_functions.cfm

9. In the root Application.cfm file I have the following.

<cfsilent>
<cfapplication name="myweb1" clientmanagement="yes"
sessionmanagement="yes" sessiontimeout="#createTimeSpan(0,0,20,0)#"
applicationtimeout="#createTimeSpan(0,0,20,0)#" loginstorage="session"
setdomaincookies="yes">

<cfscript>
if(not isDefined('application.factory') or isDefined('url.reinit')) {
application.factory=createObject('component',
'components.myweb1.factory');
}
request.factory=application.factory;
</cfscript>
</cfsilent>

10. Now you have access to any function in any page of your application.

<cfdump var="#request.factory#">
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to