-
Notifications
You must be signed in to change notification settings - Fork 27
syntax
CFML includes a set of instructions you use in pages. You will write one or more instructions in a file then run the file through a CFML engine. Three CFML instructions we will use in this tutorial are CFSET
, CFOUTPUT
, and CFDUMP
. CFSET
is used to create a variable and assign it a value. Also CFSET
is used to call methods. CFOUTPUT
displays a variable's value. CFDUMP
is used to display the contents of simple and complex variables, objects, components, user-defined functions, and other elements.
We might have a file named myprogram.cfm and Sample.cfc like this:
<cfset s = New Sample() />
<cfoutput>#s.hello()#</cfoutput>
<cfcomponent>
<cffunction name = "hello">
<cfreturn "Hello, World!" />
</cffunction>
</cfcomponent>
<cfscript>
s = New Sample();
writeOutput(s.hello());
</cfscript>
component {
public string function hello(){
return( "Hello, World!" );
}
}
For the script example, myprogram.cfm would have beginning/closing <cfscript>
tags around the instructions, however, the script-based Sample.cfc does not require <cfscript>
tags around the instructions.
<?php
require("Sample.php");
$s = new Sample();
echo $s->hello();
?>
<?php
class Sample
{
public function hello() {
return "Hello, World!";
}
}
?>
class Sample
def hello
"Hello, World!"
end
s = Sample.new
puts s.hello
Next section Variables