Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
Jtra #1
Trouble using cffunction
Hi,
I'm trying to use cffunction for the first time. My function looks like this:
<cffunction name="getTitle">
<cfargument name="lineitem">
<cfset var ret_title = "">
<cfset var id = getArtId(lineitem)>
<cfquery name="gettitle" datasource="#Application.DSN#"
username="#Application.dsn_username#" password="#Application.dsn_password#"
cachedwithin="#CreateTimeSpan(0,1,0,0)#">
SELECT title, description
FROM Artwork
WHERE artwork_id = '#id#'
</cfquery>
<cfif gettitle.recordcount>
<cfset ret_title = "#gettitle.title#">
</cfif>
<cfreturn ret_title>
</cffunction>
My call to it looks like this:
<cfset title = getTitle(lineitem)>
And the error I get looks like this:
Entity has incorrect type for being called as a function.
The symbol you have provided getTitle is not the name of a function.
What am I not understanding here?
Jtra Guest
-
cffunction problem
Well I am having big problem with coldfusion functions. I have a function in my cfm page to parse xml. In that function I have couple of variables... -
CFFunction Date Argument
Hi all! Here's the setup... In a cfc method: <cfargument name="myDate" type="date" required="no" default=""> In my calling cfm: <cfset... -
Problem with cffunction
I am getting the following error when the site is on the production server, but it works fine on my local machine. Routines cannot be declared... -
UDFs vs cffunction
Hi All, I'm very new to all this so sorry for the stupid questions and repeated topics etc. I find it easier to use UDFs than cffunctions... -
Calling a CFFUNCTION?
I am working on a form that has 3 drop down selection boxes. What I need to have happen is this: Once the first selection (Category) is made, the... -
J.C. #2
Re: Trouble using cffunction
First you need to reference the object on the page:
<CFOBJECT COMPONENT="directory1.directory2.titles" NAME="titleObj">
The "directory1.directory2.titles" is the path to the actual cfc file. (In
this example, the file is named titles.cfc) Which would be located in
/directory1/directory2/titles.cfc.
Second, you call the function like this:
<cfoutput>#titleObj.getTitle()#</cfoutput>
If your CFC has arguments, it would look like this:
<cfoutput>#titleObj.getTitle(EMPLOYEEID='12345') #</cfoutput>
JC
J.C. Guest
-
Jtra #3
Re: Trouble using cffunction
So my cffunction has to be part of a component? I thought with MX7 it didn't have to be? I'm not using a component.
Jtra Guest
-
Adam Cameron #4
Re: Trouble using cffunction
> <cffunction name="getTitle">
This creates a variables.getTitle, which hold your function.
This ALSO creates variables.getTitle... overwriting your function.> <cfquery name="gettitle" datasource="#Application.DSN#"
So it'll work fine the first time, but thereafter the function will have
replaced itself with a query, so can't call it again.
You need to VAR *all* your variables. including your queries.
<cfset var getTitle = queryNew("")>
--
Adam
Adam Cameron Guest
-
J.C. #5
Re: Trouble using cffunction
I've never used cffunction outside of a component, plus I'm not using MX7. So,
I can't answer your question. I do know that using a component works like a
champ. If you get stuck, I highly recommend using them. Reusing code rocks!
JC
J.C. Guest
-
trjlove #6
Re: Trouble using cffunction
you can also use it like this.
<cffunction name="getName" returntype="string">
<cfargument name="temp" default="">
<cfset retValue = "">
<cfset id = arguments.temp>
<cfquery datasource="itphonelist" name="q">
select * from menu where id = #id#
</cfquery>
<cfif q.recordcount>
<cfset retValue = q.displayname>
</cfif>
<cfreturn retValue>
</cffunction>
<cfoutput>#getName(1)#</cfoutput>
trjlove Guest
-
Jtra #7
Re: Trouble using cffunction
Thank you Adam!!!! I never would have figured that out :)
Jtra Guest



Reply With Quote

