ColdFusion Markup Language: Difference between revisions

Content deleted Content added
m Disambiguating links to Object-orientation (link changed to Object-oriented programming) using DisamAssist.
 
Line 181:
: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.
::<;{{tag|cfcomponent>|o}}: Defines a CFC
::<;{{tag|cffunction>|o}}: Defines the functions (methods) within a CFC
::<;{{tag|cfargument>|o}}: Defines the arguments (parameters) that a function accepts
::<;{{tag|cfreturn>|o}}: 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 <{{tag|cfinvoke>|o}} tag will create an instance of the CFC, invoke the desired method, and then destroy the instance of the CFC. <{{tag|cfinvoke>|o}} takes the name of the component (minus the .cfc extension) and the method to execute. To access any returned data, the {{mono|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 <{{tag|cfinvoke>|o}} 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.