> Hi. Is it ok to set certain application variables in
> application.cfm from
> values stored in the database?
> There are certain site-wide settings that I need to store
> in the database.
> Then do this in the application.cfm file:

> <CFIF NOT IsDefined Application.MySetting1>

> <cfquery name="myquery" dsn="dsn">
> Select Settings from db Where ....
> </cfquery

> <cfset Application.MySetting1 = myquery..MySetting1>

> </CFIF>

> My questions are:
> 1. Is it ok to set application variables using the above
> method?
> 2. If I need to update the above Application.MySetting1
> variable to a new
> value, how will I do so?

> Thanks,

> Ken.

I don't think there's anything necessarily wrong with having variables
that are both in your database and in the application scope. I would
recomment a slightly different approach. I would construct a CFC which
accepts your dsn and clientid in its init method. I assume each row of
this table represents a different client using the same application. I
would then have the init method call a fetch method which fetches the
row for the indicated client and populates values in the CFC's
variables scope. Once that had been done I would implement a
getSetting method for fetching an individual setting, and store the
CFC in your application scope, thus, rather than referencing
application.setting1 in your application, you would reference
application.appMgr.getSetting("setting1") or possibly
application.appMgr.getSetting1() if you prefer individual accessor
methods.

The advantage of this is that if you need to change the manner in
which the settings are stored or managed later, it will be easiest to
do that internally within the CFC if your application references this
method, instead of directly referencing an application variable.
Another setSetting() or individual setSetting1() methods can then
update the CFC and the database (or other storage medium)
simultanously.

Now here's the rub. Do you need to manage these settings in a central
application (one that can manage multiple client applications
simultanously) or only within each individual application? If you
don't need a centralized application for managing these, then it's
pretty straightforward, and you can use the onApplicationStart method
of your Application.cfc to instantiate and store your appMgr cfc in
the application scope.

If you need a centralized application then you'll have to find some
way to get the data into each individual application when you update
it. One way to do this is to use the cfapplication tag in your central
application to temporarily relocate the current request into the
target application and update its appMgr cfc -- the problem you'll
experience with this approach will be to ensure that the application
has already started, because if you use cfapplication to initialize
the application name, the ColdFusion server won't know where to look
for the Application.cfc and so it won't execute the onApplicationStart
method. Using a simple http request for the application's login or
home page using the cfhttp tag may be enough to ensure it's started
before making changes. An alternative would be to build a webservice
into each subordinate application, which of course brings other
challenges with it.



s. isaac dealey     434.293.6201
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework

http://www.fusiontap.com
http://coldfusion.sys-con.com/author/4806Dealey.htm


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:237305
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

Reply via email to