1 Reply Latest reply on Jul 24, 2009 3:20 PM by giarc4

    cfm template updating cfc variable scope


      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:





           <cffunction name="init" returntype="settings">




                <cfset setAppSettings() />




                <cfreturn this />









           <cffunction name="setAppSettings">




                <cfquery name="variables.qrySettings" datasource="#application.dsn#">




                     SELECT *

                     FROM SETTINGS










           <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" />








                <cfreturn local.qryResult />










      In onApplicationStart in Application.cfc, I have this line:



      application.objSettings = createObject("component","settings").init() />



        • 1. Re: cfm template updating cfc variable scope
          giarc4 Level 1

          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????