In recent days, I've actually experimented and had success just passing in a
structure and using it in the component.
I actually call the argument that was passed into function "form".
Not to be confused with the form structure, but it's name was inspired by me
passing in the form structure from the calling page.
I said to myself, "self, why don't you just keep it the same name?"

Answer.cfc:
<cfcomponent>
<cffunction name="Init">
<cfargument name="form">
<cfset Variables.Datasource = form.Datasource>
<cfset Variables.Username = form.Username>
<cfset Variables.Password = form.Password>
<cfreturn this>
</cffunction>

<cffunction name="Save">
<cfargument name="form">

<cfquery datasource="#Variables.Datasource#" username="#Variables.Username#"
password="#Variables.Password#">
Update myTable SET
myAnswer = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.myAnswer#">
WHERE AnswerID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#form.AnswerID#">
</cfquery>
</cffunction>

Application.cfc:
<cffunction name="onApplicationStart" output="False" returntype="void">
<cfset var local = {}>

<cfset local.Datasource = "myServer">
<cfset local.UserName = "xxx">
<cfset local.Password = "xxx">
<cfset Application.Answer =
CreateObject("component","com.Answer").Init(local)>
</cffunction>

Finally, on the page itself:
Answer.cfm

<cfif StructKeyExists(form,"UpdateAnswer")>
<cfset Application.Answer.Save(form)>
</cfif>

<cfform>
<input name="myAnswer">
<input name="AnswerID" type="hidden">
<input name="UpdateAnswer" type="submit" value="Update">
</cfform>


On Thu, Dec 30, 2010 at 5:05 PM, Charlie Stell <[email protected]>wrote:

> Say you have the following abc.cfc :
>
> <cfcomponent>
> ...
>  <cffunction name="x">
>   <cfargument name="a">
>   <cfargument name="b">
>   <cfargument name="c">
>   <cfargument name="d">
> ...
> </cffunction>
> ...
> </component>
>
> Ang you going to invoke in from somewhere else. Depending on the situation,
> sometimes you'll have different combinations of the arguments (for example
> maybe your using the same function to run some user search for both a simple
> and advanced mode) . Using argumentCollection, you can avoid the hassle of
> having to pass in blank values so that the positioning is right - you would
> doing something like:
> <cfset i = structnew()>
> <cfif simple_case>
>  <cfset i["a"] = form_imput_A>
> <cfelse>
>  <cfset i["b"] = form_imput_B>
>  <cfset i["c"] = form_imput_C>
>  <cfset i["d"] = form_imput_D>
> </cfif>
> <cfset results =
> createobject("component","path_to_cfc.abc").x(argumentCollection=i)>
>
> That certainly isn't an in depth example... but hope it helps some!
>
>
> On Thu, Dec 30, 2010 at 4:52 PM, Matthew Nicholson <
> [email protected]> wrote:
>
>> Afternoon All!
>>
>>
>>
>> Here’s my basic dilemma. I’m enhancing a CF application that needs a whole
>> lot of TLC. With that, I’m attempting to redesign a few aspects of the
>> application to use components to keep with good design principles.
>>
>>
>>
>> Now, I think I’m being exceptionally thick headed but I can’t for the life
>> of me figure a way to pass as argumentCollection into my component and then
>> utilize its information.
>>
>>
>>
>> Does anyone have a good resource or tutorial on how to do this? I’ve found
>> plenty that talk of using the argumentCollection but none of them illustrate
>> it’s use within the component.
>>
>>
>>
>> Thank you very much for your time and expertise!
>>
>>
>>
>> *Matthew R. Nicholson*
>>
>> *SolTech, Inc.*
>>
>> *Cell: 770-833-5326*
>>
>> *www.soltech.net*
>>
>> To find what you seek in the road of life, the best proverb of all is that
>> which says: "Leave no stone unturned."
>>       ~Edward Bulwer Lytton
>>
>>
>>
>> -------------------------------------------------------------
>> To unsubscribe from this list, manage your profile @
>> http://www.acfug.org?fa=login.edituserform
>>
>> For more info, see http://www.acfug.org/mailinglists
>> Archive @ http://www.mail-archive.com/discussion%40acfug.org/
>> List hosted by FusionLink <http://www.fusionlink.com>
>> -------------------------------------------------------------
>
>
>

Reply via email to