View comments | RSS feed
Contents > Developing ColdFusion MX Applications > Building and Using ColdFusion Components > Building ColdFusion components PreviousNext

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.


Contents > Developing ColdFusion MX Applications > Building and Using ColdFusion Components > Building ColdFusion components PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Kwin said on Aug 15, 2003 at 1:37 AM :
Insufficient documentation on recursion within CFCs. The way variables are referenced within recursive CFCs isn't intuitive, and needs a comprehensive explanation.
jrunrandy said on Mar 2, 2004 at 6:06 AM :
See the technote at http://www.macromedia.com/support/coldfusion/ts/documents/cfc_datatypes_webservices.htm for information on using CFCs to define data types for web services.
Adam Cameron said on Oct 30, 2004 at 3:14 PM :
The examples above ought to be amended to use "best practices" (more like "ESSENTIAL practices") when coding CFC methods.

Both the query resultset variables ought to be VARed at the top of the function code.
No screen name said on Feb 28, 2005 at 8:17 AM :
ODBC should not be there..its no longer in use
davenny22 said on Mar 15, 2005 at 1:56 AM :
the comment is quite scanty. Can you make it richer.

Kalu N. Idika

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/buildi35.htm