Don't know if anybody's run into this before, but I ran into a strange issue with the variable scope in a cfc. Basically, I have some application settings stored in a database table, and then I have a cfc saved to application scope in which I store the contents of the table in a variable scope query. Within the cfc, I have a getter function that preforms a query of queries to pull the data I need. I then have an admin screen within the application to update the settings.
This is (very generally) what my cfc looks like:
<cfcomponent name="settings.cfc"> <cffunction name="init" returntype="settings"> <cfset setAppSettings() /> <cfreturn this /> </cffunction>
<cffunction name="setAppSettings">
<cfquery name="variables.qrySettings" datasource="#application.dsn#">
SELECT *
FROM SETTINGS
</cfquery>
</cffunction>
<cffunction name="getAppSettings" returntype="query">
<cfargument name="id" />
<cfset var local = structNew() />
<cfquery name="local.qryResult" dbtype="query">
SELECT *
FROM variables.qrySettings
WHERE ID = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_numeric" />
</cfquery>
<cfreturn local.qryResult />
</cffunction>
</cfcomponent>
In onApplicationStart in Application.cfc, I have this line:
<cfset
application.objSettings = createObject("component","settings").init() />
Sorry, accidentally posted before I was done...
Basically, the problem is that I have an admin screen that updates the settings. I call the getter function in a cfm template, and I save the result to a variable called variables.qrySettings (same name as in the cfc) like this - <cfset variables.qrySettings = application.objSettings.getAppSettings(url.id) />. For some reason, this seems to overwrite variables.qrySettings in the cfc. Any ideas????