Skip to main content
May 8, 2008
Question

CFC question

  • May 8, 2008
  • 2 replies
  • 253 views
How do I call a function from another function in the same CFC?

For example, let's say that I have a CFC called: cart.cfc

One of the functions in the cfc is: getCartSubTotal, which takes one argument - the cart ID

Now in the same cart.cfc, I want to have a function called getShipping.

I'm thinking I should be able to pass it the same cart ID and have it get the cart sub total from the function getCartSubTotal. But how do I call that other function from the new function?



This topic has been closed for replies.

2 replies

Inspiring
May 9, 2008
inside same cfc you can call a function like
<cfset myvar = functionname(argument1, argument2, ..., argumentN)>
check out the docs for various ways to pass arguments to a function -
the above example assumes you pass args to the function in same order
they appear in the cffunction tag.

in your case, you can have code like below in your getShipping function:

<cffunction name="getShipping" access="public">
<cfargument name="cartid" type="numeric" required="yes">
<cfset var cartSubTotal = getCartSubTotal(arguments.cartid)>
....
</cffunction>

hth


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Inspiring
May 8, 2008
cfinvoke argumentcollection=arguments

is a handy piece of code.