• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Invoke a ton of components..is there an easier way?

LEGEND ,
Jan 04, 2007 Jan 04, 2007

Copy link to clipboard

Copied

I have a page that invokes about 12 CFC methods all at one using the
variable 'pcode'. Each method is a different SQL statement pulling differnet
info from the database by group.

Rather than having to invoke each individually using the same
invokeargument, is there a faster way?

For example, here is a cut from the top of my page:

<cfinvoke component="#Students#" method="ListStudents"
returnvariable="ListStudents" argumentcollection="#Form#">
<cfinvoke component="#Image#" method="MyImages" returnvariable="MyImages"
argumentcollection="#Form#">>
<cfinvoke component="#Students#" method="GetAddress"
returnvariable="GetAddress" argumentcollection="#Form#">
<cfinvoke component="#Students#" method="GPA" returnvariable="GPA"
argumentcollection="#Form#">
<cfinvoke component="#Students#" method="Education"
returnvariable="Education" argumentcollection="#Form#">
<cfinvoke component="#Students#" method="GetComments"
returnvariable="GetComments" argumentcollection="#Form#">
<cfinvoke component="#Students#" method="Academic" returnvariable="Academic"
argumentcollection="#Form#">
<cfinvoke component="#Students#" method="LSAT" returnvariable="LSAT"
argumentcollection="#Form#">

Thanks!


TOPICS
Advanced techniques

Views

218

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 04, 2007 Jan 04, 2007

Copy link to clipboard

Copied

You're not calling the COMPONENTS, you're calling the methods within the
components, which are all different. So if you need all those methods
called, then yes, you... do... have to call them.

You could cut down the number of keystrokes and make your code more
readable if you used CFScript instead of CFML, eg:

<cfinvoke component="#Students#" method="ListStudents"
returnvariable="ListStudents" argumentcollection="#Form#">
becomes:
ListStudents = Students.ListStudents(argumentcollection=Form);

The other thing you could do is to to write one more method called
doesItAll() (or something), in which you stick all that code, and
doesItAll() takes only those few arguments needed to all those method
calls, and returns one struct with all the results in it:

stResult = Students.doesItAll(argumentCollection=Form);


<cffunction name="doesItAll" returntype="struct" output="false">
<cfscript>
var stReturn = structNew(argumentcollection=arguments);
stReturn.ListStudents = ListStudents(argumentcollection=arguments);
stReturn.GetAddress = GetAddress(argumentcollection=arguments);
stReturn.GPA = GPA(argumentcollection=arguments);
stReturn.Education = Education(argumentcollection=arguments);
stReturn.GetComments = GetComments(argumentcollection=arguments);
stReturn.Academic = Academic(argumentcollection=arguments);
stReturn.LSAT = LSAT(argumentcollection=arguments);

return stReturn;
</cfscript>
</cffunction>

(note: this omits the call to the "image" component, which would still need
to be done separately)

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 04, 2007 Jan 04, 2007

Copy link to clipboard

Copied

<cfobject> or createobject would entail less code. Plus, you could write an init() method in your students.cfc that processes the form variables and makes cfc variables available to all the functions contained therein.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 04, 2007 Jan 04, 2007

Copy link to clipboard

Copied

LATEST
I will look into creating something like a doesItAll. I do use the cfobject
I just didn't include that in the page cut.

Thanks guys.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation