Let's start off by creating a folder to store our component. Under the <Railo Install Directory>/webroot
, let's create a folder named cfcs
.
1. In the
cfcs
directory, create a template namedPerson.cfc
and put the following code inside it:<cfcomponent output="false"> <cfset this.name = ""> <cfset this.age = ""> </cfcomponent>
2. This is the simplest form of a component. Let's create another template under
<Railo Install Directory>/webroot/Chapter_6/
namedPersonGetter.cfm
; this template will be used to create an instance of thePerson.cfc
object and populate it by adding the following code:<cfset person = new cfcs.Person()> <cfset person.name = "Mark"> <cfset person.age = 36> <cfdump var="#person#">
3. The
this
scope in a component is actually public. This means it can be read and modified from outside the component (as we can see in the previous code listing), which is not best practice...