> 2) You said you want to use site wide variables in a CFC. There is a
> better way of doing this then cfinclude. Your CFC could have a method,
> init(), that lets you pass these values in. Another way is to not use
> a cfinclude for your global vars, but another CFC. I typically make a
> cfc called Application, or Settings. This CFC will have one methoid,
> getSettings(). My Application.cfm file will use this method to set up
> the site wide variables in the Application scope. My other CFCs will
> call this method to set the values in the Variables scope.
I recommend to use a variables.settings structure instead of getSettings().
Because CF usually tends to use scopes/structures to make the development
easy (i think). You should set the settings structure in the constructor
method (the init()) method like the following:
<cfcomponent>
<cffunction name="init" access="public" returntype="any">
<cfargument name="settings" type="struct" required="yes"/>
<cfset variables.settings = arguments.settings />
<cfreturn this />
</cffunction>
....
</cfcomponent>
If you only need one or two specific settings in your component; you should
code your constructor like the following:
<cfcomponent>
<cffunction name="init" access="public" returntype="any">
<cfargument name="dsn" type="string" required="yes"/>
<cfset variables.dsn = arguments.dsn />
<cfreturn this />
</cffunction>
....
</cfcomponent>
This is more easy for especially traditional CFers instead of extra
inheritance or methods which cause to lead unfamiliared codes; IMHO.
Additionally you can add your global settings structure and its context in
CodeHints XML file in DWMX to make faster coding.
Murat.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:184211
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54