Adobe ColdFusion 8

Defining component methods

You define component methods using cffunction tags. The following example defines a CFC that contains two methods, getall and getsalary:

<cfcomponent>
    <cffunction name="getall" output="false" returntype="query">
        <cfset var queryall="">
        <cfquery name="queryall" datasource="cfdocexamples">
            SELECT * FROM EMPLOYEE
        </cfquery>
        <cfreturn queryall>
    </cffunction>
    <cffunction name="getsalary" output="false">
        <cfset var getNamesandSalary="">
            <cfquery name="getNamesandSalary" datasource="cfdocexamples">
                SELECT FirstName, LastName, Salary FROM EMPLOYEE
            </cfquery>
        <cfreturn getNamesandSalary>
    </cffunction>
</cfcomponent>

Because component methods are ColdFusion functions, most of their features and coding techniques are identical to those of user-defined functions. For more information on using the cffunction tag to create functions, see Writing and Calling User-Defined Functions. Like other ColdFusion functions, CFC methods can display information directly by generating output, or can return a value to the code or client that invoked the method.

You use the following cffunction tag attributes only for CFCs:

  • The displayname and hint attributes, which document the CFC; for more information, see Documenting CFCs.
  • The access attribute, which controls access to the CFC; for more information, see Using access security.

For detailed reference information on the cffunction tag, see the CFML Reference.