Skip to main content
nikos101
Inspiring
May 26, 2009
Answered

How to you refer to a function in another function in a cfc

  • May 26, 2009
  • 2 replies
  • 2993 views

HI,

How to you refer to a function in another function in a cfc like so

<cffunction name="getApplicationConstants" access="remote" returntype="struct">
   
 
         <cfset flash.result.users = [the result from the getUsers function]>
    <cfreturn flash.result>
</cffunction>

<cffunction name="getUsers" access="remote" returntype="query">
   
        <cfquery name="q" datasource="#datasource#">
            select     c.*
            from    USERS as c    WHERE looksLikeUserIsDeleted = 'False'
            AND userPrivileges = 1
           
            ORDER BY fullName
       
       
        </cfquery>

        <cfset flash.result = q>
        <cfreturn flash.result>
</cffunction>

This topic has been closed for replies.
Correct answer craigkaminsky

Hi, Nikos,

If the CFCs are in the same directory, you could do the following:

CFCA

<cfcomponent>

<cffunction name="getApplicationConstants" access="remote" returntype="struct">
    <cfset flash.result.users = cfcB.getUsers() />
    <cfreturn flash.result>
</cffunction>

</cfcomponent> 

CFCB

<cfcomponent>

<cffunction name="getUsers" access="remote" returntype="query">   
        <cfquery name="q" datasource="#datasource#">
            select     c.*
            from    USERS as c    WHERE looksLikeUserIsDeleted = 'False'
            AND userPrivileges = 1
            ORDER BY fullName       
        </cfquery>

        <cfset flash.result = q>
        <cfreturn flash.result>
</cffunction>

<cfcomponent>

If the CFCs were in different directories, the cfset expression in CFCA would be this:

<cfset flash.result.users = path.to.cfc.cfcB.getUsers() />

Where I have path.to.cfc, you would use either a mapping from CF Admin or the hierarchy of folders to the CFC from the web root.

Does that help?

2 replies

craigkaminskyCorrect answer
Inspiring
May 26, 2009

Hi, Nikos,

If the CFCs are in the same directory, you could do the following:

CFCA

<cfcomponent>

<cffunction name="getApplicationConstants" access="remote" returntype="struct">
    <cfset flash.result.users = cfcB.getUsers() />
    <cfreturn flash.result>
</cffunction>

</cfcomponent> 

CFCB

<cfcomponent>

<cffunction name="getUsers" access="remote" returntype="query">   
        <cfquery name="q" datasource="#datasource#">
            select     c.*
            from    USERS as c    WHERE looksLikeUserIsDeleted = 'False'
            AND userPrivileges = 1
            ORDER BY fullName       
        </cfquery>

        <cfset flash.result = q>
        <cfreturn flash.result>
</cffunction>

<cfcomponent>

If the CFCs were in different directories, the cfset expression in CFCA would be this:

<cfset flash.result.users = path.to.cfc.cfcB.getUsers() />

Where I have path.to.cfc, you would use either a mapping from CF Admin or the hierarchy of folders to the CFC from the web root.

Does that help?

nikos101
nikos101Author
Inspiring
May 27, 2009

thanks

nikos101
nikos101Author
Inspiring
May 27, 2009

What if both my functions are in the same component?

Michael Borbor
Inspiring
May 26, 2009

You could use cfinvoke