How to invoke a method of a component in ColdFusion

cfcomponent and cfinvoke - invoke a method of a component

cfcomponent.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfcomponent and cfinvoke tag example: how to invoke a method of a component</title>
</head>

<body>
<h2 style="color:DodgerBlue">ColdFusion cfcomponent and cfinvoke example</h2>

<cfinvoke 
 component="DataViewer" 
    method="GetTableData" 
    DSname="cfdocexamples"
    Table="Employees" 
    returnvariable="qTableData"
    >
<cfdump var="#qTableData#">

</body>
</html>

DataViewer.cfc


<cfcomponent hint="Table Data Viewer">
 <cffunction name="GetTableData" access="remote" returntype="query">
  <cfargument name="DSname" type="string" required="yes">
        <cfargument name="Table" type="string" required="yes">
  <cfquery name="qTable" datasource="#arguments.DSname#">
         SELECT * FROM #arguments.Table#
        </cfquery>
  <cfreturn qTable>
 </cffunction>
</cfcomponent>





More ColdFusion examples