Question for the list.  It has to do with what appears to be object reference
with data stored in a cfc.  Any help you got would be great, oh yeah, and kind
of an emergency fo us!  Coming up on a deadline fast!

It is my understanding that when you "<cfset var var_myvar = "">" (var out a
variable) you capture information at a function level not at a component level.  
Therefore if I have a data collection in a component that I want to grab,
analyze, edit, and send to the user without editing the original shared
component version I can just grab it using the var scope.  Once in the var scope
I can make my edits without affecting the original shared scope version.  Maybe
a description will better explain this:

Here is the code I am using to access and modify my component:

<!--- create and initialize the test object in local memory --->
<cfset variables.test = createObject("component", "cf_components.test")>
<cfset variables.test.initializeObject()>

<!--- get and dump the data for this customer  --->
<!--- you should see two keys "firstname" and "lastname" --->
<cfdump var="#variables.test.getCustData()#">

<!--- perform a customer analysis, this customer analysis should return a
structure with a new "description" key in it --->
<!--- Inside the function I have scooped the component level customer
information by using a getter on the original shared data --->
<!--- Thre returnvariable dumps the data into the var scope.  My edits should
remain only in that vared out variable --->
<!--- with the "firstname", "lastname", and "description" field contained in
var_stCustomerData --->
<cfdump var="#variables.test.customerAnalysis()#">

<!--- get the customers original data.  This data sits in the shared scope of
the test object and should not reflect the changes made in customerAnalysis to
the vared version --->
<!--- I should only see two keys "firstname" and "lastname" however the edit
performed in customerAnalysis (on the vared version of the data) edits the
original information putting description in the shared component version --->
<cfdump var="#variables.test.getCustData()#">

Here is my cfc:
<cfcomponent displayname="test" hint="I am a component that test references to
stored data.">
  
<cffunction name="initializeObject" hint="I prepare the object by setting some
intial data" access="public" output="no" returntype="boolean">

  <!--- Set up the customer object --->
  <cfscript>
   
  this.objName = "customer";
   
  // Set up the customer object data containers
  stCustomerInfo        = structNew();
  stCustomerInfo.firstname     = "michael";
  stCustomerInfo.lastname      = "hodgdon";

  </cfscript>   

  <cfreturn "1">
  
</cffunction>

<cffunction name="getCustData" hint="I return the customer data"
access="public" output="no" returntype="struct">
  
  <cfreturn stCustomerInfo>  
  
</cffunction>

<cffunction name="customerAnalysis" access="public" output="no"
returntype="any">
  
  <cfset var var_stCustomerData = "">


  <!--- grab the customer data and place it in a local variable --->
  <cfinvoke
   method="getCustData"
   returnvariable="var_stCustomerData">
  
  
  <!--- if your name is michael --->
  <cfif var_stCustomerData.firstname EQ "michael">
   
   <!--- add to the temp local var a customer description --->
   <cfset structInsert(var_stCustomerData, "description", "Your name is mike")>
   
   
  <!--- your name is not michael  --->
  <cfelse>
  
   <!--- add to the temp local var a customer description --->
   <cfset structInsert(var_stCustomerData, "description", "Your name is not
mike")>   
   
  </cfif>
  
  <!--- return the edited customer information --->
  <cfreturn var_stCustomerData>  
  
</cffunction>

</cfcomponent>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to