UDF:

<cffunction name="whatever" ...>
  <!--- ... --->
</cffunction>

CFC:

<cfcomponent>
  <cffunction name="whatever" ...>
    <!--- ... --->
  </cffunction>
</cfcomponent>

To call them you do this:

UDF:
<cfinclude template="myudf.cfm" />
<cfset whatever() />

CFC:
<cfinvoke component="mycfc" method="whatever" />

If you CFC is in the same directory as your calling code, you only need the
root of the filename (not the extension).  If it's in a different directory,
you'll need the full path.
  -----Original Message-----
  From: Bryan Stevenson [mailto:[EMAIL PROTECTED]
  Sent: Thursday, October 23, 2003 2:32 PM
  To: CF-Talk
  Subject: Re: CFCs and UDFs

  Thanks guys....I figured as much ;-)

  So how would I go about creating a CFC from an exisitng UDF (like the many
found on CFLIB)?

  Thanks
    ----- Original Message -----
    From: Barney Boisvert
    To: CF-Talk
    Sent: Thursday, October 23, 2003 2:07 PM
    Subject: RE: CFCs and UDFs

    You shouldn't need to.  If you need a utility function, it should be a
    method of the CFC you're in.  CFCs should stand on their own as much as
    possible, so they don't need any external resources (other than method
    arguments) to function.  That's not always possible, but it usually is.

    If you really have a function you need to use, and it doesn't make sense
to
    put the function in the CFC directly, put it in another CFC that you
don't
    instantiate, you just call methods on statically.  In other words,
CFINVOKE
    with the name of the CFC, not CFOBJECT or createObject() and then a
method
    call on the object.  You can then call that method from your CFC as if
it
    where a UDF, and you don't have to include it anywhere first.

    barneyb
      -----Original Message-----
      From: Bryan Stevenson [mailto:[EMAIL PROTECTED]
      Sent: Thursday, October 23, 2003 1:57 PM
      To: CF-Talk
      Subject: CFCs and UDFs

      Hey All,

      Can  a UDF be used inside a CFC is the UDF is included in the template
    that
      calls the CFC? or the UDF is included via Application.cfm?

      From what I've seen it cannot...but mabye my info is off ;-)

      TIA

      Cheers

      Bryan Stevenson B.Comm.
      VP & Director of E-Commerce Development
      Electric Edge Systems Group Inc.
      t. 250.920.8830
      e. [EMAIL PROTECTED]

      ---------------------------------------------------------
      Macromedia Associate Partner
      www.macromedia.com
      ---------------------------------------------------------
      Vancouver Island ColdFusion Users Group
      Founder & Director
      www.cfug-vancouverisland.com


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to