Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ColdFusion Markup Language
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== ColdFusion Components (CFCs) == CFCs provide some (not all) of the typical features and functionality that are provided by [[object-oriented]] (OOP) languages. To create a CFC: :Create a file with a .CFC extension (this distinguishes CFCs from ColdFusion templates, which have a .CFM extension). :Use four tags to create the components, define their functions and [[arguments]], and return a value. ::<cfcomponent>: Defines a CFC ::<cffunction>: Defines the functions (methods) within a CFC ::<cfargument>: Defines the arguments (parameters) that a function accepts ::<cfreturn>: Returns a value or result from a function CFCs are plain CFML. Within a CFC any CFML tag, function, custom tag, other components, etc. may be used. CFCs can be used in various ways. If a method contained in a CFC simply needs to be invoked, the <cfinvoke> tag will create an instance of the CFC, invoke the desired method, and then destroy the instance of the CFC. <cfinvoke> takes the name of the component (minus the .cfc extension) and the method to execute. To access any returned data, the RETURNVARIABLE attribute provides the name of a variable to contain whatever the function returns. CFCs are created using four tags, saved as .CFC files, and invoked using the <cfinvoke> tag.<ref>Forta, Ben [https://web.archive.org/web/20100528103657/http://www.adobe.com/devnet/coldfusion/articles/intro_cfcs.html Using ColdFusion components]. adobe.com</ref> In the example below, component temperature.cfc has a method FtoC which converts temperature from Fahrenheit to Celsius. The test.cfm template invokes the method and converts 212 degrees Fahrenheit and outputs the result. <syntaxhighlight lang="cfm"> <!--- temperature.cfc ---> <cfcomponent> <cffunction name="FtoC" access="public" returntype="numeric"> <cfargument name="fahrenheit" required="yes" type="numeric" /> <cfset answer= (fahrenheit - 32)*100/180 /> <cfreturn answer /> </cffunction> </cfcomponent> <!--- test.cfm ---> <cfset fDegrees = 212 /> <cfinvoke component="temperature" method="FtoC" returnvariable="result"> <cfinvokeargument name="fahrenheit" value="#fDegrees#" /> </cfinvoke> <cfoutput>#fDegrees#°F = #result#°C</cfoutput> <br /> </syntaxhighlight> CFCs may also be instantiated as objects. Assuming a CFC file called Person.cfc, an instance of this CFC would be instantiated as follows: <syntaxhighlight lang="cfm"> <cfset person = CreateObject("component", "Person") /></syntaxhighlight> CFCs also form the basis of the ability to create [[web services]] in CFML. A CFC is created in the usual way, and the attribute access="remote" added to any function within the CFC will make that function available to be called as a [[SOAP]]-based web service. The CFML engine auto-generates a [[Wsdl|WSDL]] and creates all the necessary stubs for the web service to function.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)