Building ColdFusion components

You use the cfcomponent and cffunction tags to create ColdFusion components. By itself, the cfcomponent tag does not provide functionality. Rather, the cfcomponent tag provides an envelope that describes the functionality that you build in CFML and enclose in cffunction tags.

The following example creates a component with two methods:

<cfcomponent>
   <cffunction name="getEmp">
       <cfquery name="empQuery" datasource="ExampleApps" dbtype="ODBC" >
          SELECT FIRSTNAME, LASTNAME, EMAIL
          FROM tblEmployees
       </cfquery>
       <cfreturn empQuery>
   </cffunction>
   <cffunction name="getDept">
      <cfquery name="deptQuery" datasource="ExampleApps" dbtype="ODBC" >
          SELECT *
          FROM tblDepartments
       </cfquery>
       <cfreturn deptQuery>
   </cffunction>
</cfcomponent>

In the example, two cffunction tags define two component methods, getEmp and getDept. When invoked, the component methods query the ExampleApps database. The cfreturn tag returns the query results to the client.

The following sections discuss how you define components and their methods.

View comments on LiveDocs