3
votes

I'm trying to create basically a library of UDFs (User Defined Functions) for a web site run in ColdFusion. While doing this I am trying to find out what the differences are between cfc and cfm files. Which would be more helpful in creating this library of functions? I know that I can use

<cfinclude template="mytemplate.cfm>

to include it in a page but that will run the entire contents of that cfm on that page every time. I don't know and easier way to use cfc other than to create an object of the cfc and call the function that way.

<cfobject type="component" action="create" name="test">

Any ideas?

2
Did you do a search first? Because there are many good threads on the topic, both on Stack Overflow and various blogs. For example stackoverflow.com/questions/624541/… - Leigh
This one too that also includes using component.cfc option stackoverflow.com/a/13763078/244136 - genericHCU

2 Answers

3
votes

The way that I do it is to create all my UDF in a cfc. I then initialize that cfc on application start:

public function onApplicationStart() {
    // Application settings
    application.util = createObject("component","cfc.util");
    return;
}
-1
votes

use a cfc you can call more easily from more places, if its not too huge put it into your application scope