ColdFusion - How to invoke a method of a component

cfinvoke and cfinvokeargument - invoke a method of a component

cfinvokeargument.cfm


<!DOCTYPE html>

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

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

<cfinvoke 
 component="TableData" 
    method="GetTableData" 
    returnvariable="qTableData"
    >
 <cfinvokeargument name="Table" value="Employees">
    <cfinvokeargument name="Columns" value="FirstName,LastName,Email">
</cfinvoke>    
<cfdump var="#qTableData#">

</body>
</html>



TableData.cfc


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





More ColdFusion examples