N00b here making slow headway turning spaghetti code into more suitable code.
I am tinkering with a very simple CFINVOKE of a component. On the page is this:
<cfinvoke
component="Products"
method="get_active_products"
returnvariable="p"
specificProduct="BA100">
</cfinvoke>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Component Play</title>
</head>
<body>
<p>Hi.</p>
<cfdump var="#p#">
</body>
</html>
And in Product.cfc is this:
<cfcomponent displayname="Active Products CFC" hint="Gets all active catalog products">
<!--- This function gets all the active products and their data from the DB --->
<cffunction name="get_active_products" hint="Gets active products in the database" returntype="query">
<!--- identify arguments --->
<cfargument name="specificProduct" type="string" required="no">
<!--- if we get a value, add it to the query --->
<cfif IsDefined(arguments.specificProduct)>
<cfset whereClause="AND prod_code = " + specificProduct>
<cfelse>
<!--- and if we don't, just make it blank --->
<cfset whereClause="">
</cfif>
<!--- now query for active products... --->
<cfquery name="get_em" datasource="#application.datasource#">
select * from tblProducts
WHERE prod_status != '4' and prod_status != '8' and prod_status != '11'
#whereClause#
</cfquery>
<!--- and return the dataset --->
<cfreturn get_em>
</cffunction>
</cfcomponent>
HOWEVEVER... It never seems to see arguments.specificProduct as having a value, thus always just returns all products. I've read a lot about CFINVOKE, CFCOMPONENT and all the ways to reference a variable... and tried them all! This is so simple. What's amiss?
Thanks.