Wednesday, January 12, 2005

A ColdFusion component snippet

Here is a code snippet I use to get my components started. Unfortunately, I've had to play with the formatting a bit to get it to display in this blog format. If anybody knows of a good code posting plugin for blogger.com, please let me know.

<!--- *****************************************************************
Original Author: Mike Rankin
Original Date: 1/7/2005
Description: Basic component template. Modify this section to work with
your source control program. This is built for VSS.
$Archive: $
$History: $
$NoKeywords: $
****************************************************************** --->
<cfcomponent displayname="myClass" hint="Description of myClass" extends="components.base">

<!--- =============================================== --->
<!--- Declarations --->
<!--- =============================================== --->
<cfproperty name="aPrivateProperty" type="" hint="">

<!--- =============================================== --->
<!--- Constructor --->
<!--- =============================================== --->
<cffunction name="_init" access="public" output="false" returntype="" displayname="Constructor">
<cfscript>
// initialize all propeties
variables.aPrivateProperty = "";
// test for overloading. If true, load object from db with a call
// to a db method
// _load(key);
return this;
</cfscript>
</cffunction>

<!--- =============================================== --->
<!--- Database Methods --->
<!--- =============================================== --->
<cffunction name="_load" access="private" output="false" returntype="void" displayname="Loader" hint="Loads myClass instance from database">
<cfargument name="key" required="yes" type="string">
<cfquery name="" datasource="#application.ds#">
SELECT fieldlist
FROM my Table
WHERE myTable.key = '#arguments.key#'
</cfquery>
</cffunction>

<!--- =============================================== --->
<!--- Operational Methods --->
<!--- =============================================== --->

<!--- =============================================== --->
<!--- Getters --->
<!--- =============================================== --->
<cffunction name="getAPrivateProperty" access="public" output="false" returntype="string">
<cfreturn aPrivateProperty>
</cffunction>
<!--- =============================================== --->
<!--- Setters --->
<!--- ===============================================--->
;</cfcomponent>

No comments:

Post a Comment