Skip to main content
February 18, 2009
Question

CFINVOKE and its argumentcollection attribute

  • February 18, 2009
  • 1 reply
  • 1191 views
I'm passing a structure into a cfc using cfinvoke. I use argumentcollection attribute of the cfinvoke to pass this structure to my cfc (I don't know any other ways to do this, are there alternative?)
After doing some reading, I was able to pass my structure as explained in the code below.
My question is: Since all the arguments are now of type string then within my cfc I have no strcuture anymore, am I right?
If I still want to use a structure on my further coding I need to assemble a structure again using all the arguments that were passed??????

<cfset var result = "">
<cfset var myStruct = structNew()>
<cfset myStruct["a"] = 1>
<cfset myStruct["b"] = 2>
<cfset myStruct["c"] = 3>

<cfinvoke argumentcollection="#myStruct#" component="Comp2" method="handleArgCollection"
returnvariable="result" />

Within the cfc these are what I have:

<CFFUNCTION name="handleArgCollection">
<cfargument name="a" required="yes" type="string">
<cfargument name="b" required="yes" type="string">
<cfargument name="c" required="yes" type="string">

If I do something with myStruct, I got an error since myStruct is no longer exist (?)
So if I want to work with these argument parameters as a strcuture within this function do I have to re-create
a structure again using all those arguments???????


</CFFUNCTION>


This topic has been closed for replies.

1 reply

Inspiring
February 18, 2009
BYJ_wntrsnt wrote:
> So if I want to work with these argument parameters as a strcuture within this
> function do I have to re-create
> a structure again using all those arguments???????


If you want a structure in your component's function, pass a structure.

<cfset myStruct = {foo="bar", george="gracie", ten="10">

<cfinvoke component="Comp2" funcStruct=myStruct
method="handleArgCollection" returnvariable="result">

<cffunction name="handleArgCollection">
<cfargument name="functStruct" requred="yes" type="struct">




The purpose of the argumentCollection property is the ability to treat
all the arguments of a function as a structure so that they can be
manipulated as such if that is desired by the developer.


<cfset myStruct = {foo="bar", george="gracie", ten="10">
<cfset arguments = {name="test" funcStruct=myStruct}

<cfinvoke component="Comp2" argumentcollection=arguments
method="handleArgCollection" returnvariable="result">

<cffunction name="handleArgCollection">
<cfarguments name="name" required="yes" type="string">
<cfargument name="functStruct" requred="yes" type="struct">