SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    975
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calling a cfc from cfset tag

    So I found this pdf from c.arehart about the many ways of calling a cfc.

    http://www.fusionauthority.com/tipical-charlie/

    Second page says you can invoke via cfset like so:
    Code CFM:
    <cfset returnvariable = instancename.methodname()>

    So, let say I have a cfc directory in my root and in that I have a cfc called 'test' with a method 'hello'.
    Code CFM:
    <cfset variables.hello = test.hello()>
    <cfoutput>#variables.hello#</cfoutput>

    Gives me an error saying "variable 'test' doesn't exist. I understand why I'm getting the error, but how does the server know what directory to look into to find the cfc. I like this method if this is possible over cfobject or cfinvoke. I even tried putting the cfc in the same directory as the cfm file…*still error.

    Any insight is appreciated.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to create an instance of the cfc first.

    Code:
    <cfset variables.test = createObject("component", "path.to.YourComponent")>
    <cfset variables.hello = test.hello()>
    ...

    how does the server know what directory to look into to find the cfc
    See "Specifying the CFC location"

    http://livedocs.adobe.com/coldfusion...onents_27.html

  3. #3
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    975
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well that's a bummer…&#160;thought it sounded too good to be true.

    If I HAVE to use the createObject function, I'll just put the method at the end of the object call and just have one cfset.

    Thanks for the help.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, that is essentially what cfinvoke does - creates the object and then calls the specified method. Personally I find cfinvoke too bulky for my tastes, so I use createObject instead.

    Of course if you are working with a stateless component (like a utility cfc, etc... ) , you can create the object once in your Application.cfc then call it from any of your pages.

    <cfset variables.results = application.someVariableName.hello()>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •