Adobe COLDFUSION 9 Manual page 31

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<!---mail and ftp service --->
<cfscript>
m = new mail();
<!---mail service --->
m.setTo("x@adobe.com");
<!---set attribute using implicit setter --->
m.setSubject("Hi");
m.setBody("test mail");
<!---users need to use 'body' to specify cfmail and cfmailpart content --->
m.addparam(file="#E xpandPath('test.txt')#");
<!---add cfmail param tags --->
m.addPart(type="html",charset="utf-8",body="some
mailpart content");
<!---add cfmailpart tags --->
m.send(to="y@abc.com" ....);
<!---attributes can be overriden when sending mail --->
m.clear();
<!---clearAttributes(),clearParams() and clearParts() can also be used to clear --->
individual items, if needed
<!---ftp service --->
f = new ftp(server="s",username="u",password="p");
<!---check if a specified directory already exists (note the usage of getPrefix ())--->
f.existsDir(directory ="some_dir").getPrefix().returnValue ? WriteOutput("Directory
exists"):WriteOutput("Directory does not exist");
<!---list directory contents (note the usage of getResult() and getPrefix() --->
r = f.listDir(directory="some_dir",name="dirContents");
dirContents = r.getResult();
r.getPrefix().succeeded ? WriteOutput("List Directory operation successful") :
</cfscript>
<!---http service --->
<cfscript>
httpObj = new http();
<!---example 1 --->
<!---add params--->
httpObj.addParam(type="cgi", Name="Content-type", value =
"application/x-www-form-urlencoded",encoded="no");
httpObj.addParam(type="body",value="test1=value1&test2=
value2&arraytest=value1&arraytest=value2");
<!---assign the component returned to a variable--->
r = httpObj.send(url="http://localhost:8500/
project1/cfscript_test_files/thread-
safe/http/_cfhttpparam_body.cfm",method="POST");
<!---use getPrefix() to dump the cfhttp prefix --->
writedump(r.getPrefix());
<!---example 2 --->
<!---using attributes that return a query --->
r = httpObj.send(url="
http://localhost:8500/language_enhancements_2/cfscript_test_files/thread-
safe/http/vamsee.txt")",name="myqry", firstrowasheaders="no",method="GET");
<!---dump result and name attributes data --->
writedump(r.getPrefix());
writedump(r.getResult());
</cfscript>
Last updated 8/5/2010
26

Advertisement

Table of Contents
loading

Table of Contents