Pseudo-constructors
In Chapter 1, Introducing ColdFusion Components we looked at how to create an instance of a ColdFusion component using the createObject()
function. We also looked at how to pass values through to the instantiated object upon creation using the init()
method (also known as the object constructor method), thereby making them available to all methods within the CFC.
You can use any CFML tags or CFScript code within your component document to create your constructor code, and typically it is best practice to place the constructors at the top of the document, directly beneath the opening cfcomponent
tag and before any method definitions.
ColdFusion provides an alternative method for setting your CFC-wide variables in your component, using a pseudo-constructor. This term simply refers to the code contained within the cfcomponent
tags but outside of a cffunction
block.
A pseudo-constructor's role is to set variables, run queries, or run any code during the instantiation of the...