3

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?

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
jkw4703
  • 352
  • 3
  • 17
  • 1
    Did you do a search first? Because there are many good threads on the topic, both on Stack Overflow and various blogs. For example http://stackoverflow.com/questions/624541/how-do-you-organize-your-small-reusable-cffunctions – Leigh Apr 02 '13 at 19:50
  • This one too that also includes using component.cfc option http://stackoverflow.com/a/13763078/244136 – genericHCU Apr 02 '13 at 21:04

2 Answers2

4

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;
}
Leigh
  • 28,765
  • 10
  • 55
  • 103
Sollinger04
  • 385
  • 1
  • 9
  • 2
    @jkw4703 - Just be sure the functions are stateless and all function variables are localized to avoid threading problems. – Leigh Apr 02 '13 at 19:46
0

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

  • 3
    The question was whether to use an include or a CFC. @matthew-bourke answered it. It's not the best answer here, but it answers the question as asked. Bear in mind the question was very poorly researched so doesn't really merit anything more than a superficial answer. – Adam Cameron Apr 03 '13 at 03:17