macromedia.coldfusion.cfml_general_discussion
[Top] [All Lists]

Re: Call a function within the same CFC component

Subject: Re: Call a function within the same CFC component
From: GArlington
Date: Fri, 17 Aug 2007 09:17:39 -0700
Newsgroups: macromedia.coldfusion.cfml_general_discussion
On Aug 17, 3:54 pm, "Philippe Forget" <[email protected]>
wrote:
> OK I solved it with your tips !!!
>
>  Here is the final code for the others...
>
>  <!--- Start of %root%/page.cfm --->
>
>  <!--- Instanciate component --->
>  <cfobject component="admin._components.test" name="objTest">
>
>  <cfinvoke component="#objTest#" method="coolfunction" 
> returnvariable="result">
>
>  <cfdump var="#result#">
>
>  <!--- End of %root%/page.cfm --->
>
>  <!--- Start of %root%/_components/test.cfc --->
>  <cfcomponent>
>
>         <cffunction name="coolfunction" access="public" returnType="any"
> output="true">
>         <cfset var myReturn="">
>          <cfinvoke
>                         method="superfunction"
>              returnVariable="myReturn"
>                         myArg1="tata"
>                         myArg2="titi">
>                 </cfinvoke>
>          <cfreturn myReturn>
>      </cffunction>
>
>      <cffunction name="superfunction" access="private" returnType="any"
> output="true">
>         <cfargument name="myArg1" type="string">
>          <cfargument name="myArg2" type="string">
>         <cfset var myVariable = arguments.myArg1 &" toto "& arguments.myArg2 
> />
>          <cfreturn myVariable>
>      </cffunction>
>
>  </cfcomponent>
>
>  <!--- End of %root%/_components/test.cfc --->

Final question: why do you invoke another copy of the same component
to call this function?
<cfcomponent>
<cffunction name="Func1" >
<cfset retVar = Func2(param1...) />
</cffunction>

<cffunction name="Func2" >
<cfargument ... />
... Do something here
</cffunction>
</cfcomponent>


<Prev in Thread] Current Thread [Next in Thread>