This example shows the structure of a CFC using the cfdump tag to dump the CFC to the screen. What you see on your screen is actually a dump of the Employee Object. The example is using the Northwind SQL 2000 database with two stored procs that I wrote for this example. The source code of the CFC itself is shown in the source window (scroll down).

The CFC, otherwise known as a class, contains three methods: new(), setTerritories(), and getTerritories(). The new() method does not have any return type and is set to access level public, meaning we can access it from anywhere in the application. By not having a return type and using the "this" scope in the CFC, I can just define properties of the object. The setTerritories() method is accessible privately, meaning, it can only be accessed by another method within the CFC. The setTerritories() method returns an array datastructure. Note that I've embedded this array structure in the Employee object -- because this is a "has-a" relationship -- an Employee HAS Territories. If I were to call the getTerritories() method once I've instantiated this employee object, I'd just get back the array data structure.

The code to instantiate this object is this:

<cfscript>
NWEmployee = CreateObject('component', 'quagmire.components.northwind_employee');
NWEmployee.new(employeeId = "1");
</cfscript>

component quagmire.components.northwind_employee
EMPLOYEEID 1
LASTNAME Davolio
DSN Northwind
FIRSTNAME Nancy
TERRITORIES
array
1
array
1 06897
2 Wilton
2
array
1 19713
2 Neward
NEW
function new
Arguments:
Name Required Type Default
employeeId Required numeric  
Return Type: void
Roles:  
Access: public
Output: Yes
GETEMPLOYEELIST
function getEmployeeList
Arguments:none
Return Type: query
Roles:  
Access: public
Output: Yes
GETPRODUCT
function getProduct
Arguments:
Name Required Type Default
ProductName Required string  
Return Type: query
Roles:  
Access: public
Output: Yes
GETPRODUCTDETAIL
function getProductDetail
Arguments:
Name Required Type Default
ProductId Required numeric  
Return Type: query
Roles:  
Access: public
Output: Yes
GETTERRITORIES
function getTerritories
Arguments:none
Return Type: array
Roles:  
Access: public
Output: Yes


Source Window: