Cffunction, cfscript, script, within .cfc files

My background is with a decade ago, and PowerShell functions as of last week. Functions. Gotta have 'em.

I’m missing something in understanding functions within CF, correct syntax, where they need to be placed, and the correct syntax on how to call them from a(ny) .cfm.

My understanding is that functions should be placed in the/an application.cfc file, although I also understand anything in the application.cfc will be run at launch before the event functions, and I also find many application.cfc files in various sample projects.

I’m seeing that functions can be coded as simply as:

public string function sayHello(mytext) {
    var myFunctionText = myText;
        return myFunctionText;

or as:

	hint="Fires when the application is first created.">

	<!--- Return out. --->
	<cfreturn true />

leaning on the .cfc event functions.

I can save a ‘function’ within the application.cfc without the .cfc failing and returning a blank screen, but I’m not understanding what it looks like to call the function from within a .cfm to pass to it, operate it, and collect the result.

I’ve been trying many combinations but haven’t found one functional.

Usual results are:
No matching function [SAYHELLO] found

Interesting: within index.cfm
14 reed = sayhello(“text”)
15 This is #reed# <!— outputting “no”, the default —>
17 <cfset reed = sayhello(“text”)/>
18 #reed#

In trying to call sayhello in application.cfc:
public string function sayHello(mytext) {
var myFunctionText = myText;
return myFunctionText;

Balks at line 17 "
Lucee Error (expression)
Message No matching function [SAYHELLO] found

Implying that line 14 is valid in at least it’s not bounced…

Good karma in return for any advice…

OK, that understanding is incorrect.

Can I recommend you work through the docs here to start with: Build and use ColdFusion Components

That should get you on the right initial track.

At this stage, that’s the best first thing to do rather than ppl offering tutorials via a web forum, I reckon.


I appreciate the link. Much of the “Here’s how to… in CF” bits I’ve been finding were fairly bland (in that they lacked detail). This looks complete and relative.

Ooooh, methods, not functions. Right of the bat…