Skip to main content
Inspiring
May 16, 2008
Question

Invoking component from cffunction

  • May 16, 2008
  • 5 replies
  • 3024 views
Hi all,

I had a script in CF7 that used cfinvoke to call a cffunction from inside a different cffunction tag within the same cfcomponent tag. This all worked fine on my old CF7 server, but now on a new CF8 server it throws an error saying "Could not find the ColdFusion Component or Interface CFC.shoppingCart."

Any ideas anyone?

Thanks, Paul

    This topic has been closed for replies.

    5 replies

    BKBK
    Community Expert
    Community Expert
    May 17, 2008
    All's well that ends well.




    BKBK
    Community Expert
    Community Expert
    May 17, 2008
    Could there be a name/type clash? What happens when you give the function a new name?

    Inspiring
    May 17, 2008
    BKBK,

    I have recently changed the returned variable name as it was the same as the calling function and having tested in a different browser, it seems to work now.

    I suspect that was the cause from the beginning - I never had that problem with CF7.1 though. Something new in CF8?
    BKBK
    Community Expert
    Community Expert
    May 17, 2008
    If you get the same error, then you're calling the function from a page relative to which the CFC's path is different from CFC.shoppingCart. There are three paths to consider. What is the path of the shoppingCart CFC, of the page containing the function and of the page that calls the function?

    Inspiring
    May 17, 2008
    BKBK,

    The calling page is mysite.com/page.cfm and it calls the cfc as cfc.shoppingCart.
    The shoppingCart cfc is mysite.com/cfc/shoppingCart.cfc

    The error it gives is Entity has incorrect type for being called as a function.

    Thanks,
    Paul
    Inspiring
    May 16, 2008
    Trying to get a shared hosting provider to restart a service on their boxes can be quite a frustrating task. If for some reason you can't test the application on a local development machine, you could always just change the name of the CFC and test against the new CFC. You shouldn't have any problems with coldfusion pointing to an old version of the component.
    Inspiring
    May 16, 2008
    > "Could not find the ColdFusion Component or Interface CFC.shoppingCart."

    > <cfinvoke component="CFC.shoppingCart" method="getCartProduct"
    > returnvariable="getCartProduct">


    Can you browse to http://yoursite/CFC/shoppingCart.cfc?

    Do you have a CF mapping called CFC, pointing to the dir that has
    shoppingCart.cfc in it?

    CF needs to know how to find the CFC file.


    --
    Adam
    Inspiring
    May 16, 2008
    > uses cfinvoke to call another cffunction in the same cfcomponent.

    Sorry, didn't see the reference to "the *same* component" before. As per
    Ian's comment, one ought not use the component attribute of <cfinvoke> if
    it's a local method. I just saw the code and ass-u-me'd.

    But this leads me to spot another potential problem with your code.
    Although it'll not be what's causing your current problem; it'll be a
    problem if you take Ian's remedial action.


    > <cfinvoke component="CFC.shoppingCart" method="getCartProduct" returnvariable="getCartProduct">

    More specifically:

    > method="getCartProduct"
    > returnvariable="getCartProduct"

    A method within a CFC instance is just a variable (in the variables scope).

    The returnvariable of a cfinvoke call sets a variable. If one doesn't
    first VAR that variable, then it will be placed in the variables scope.

    In this case, your return variable will overwrite your function variable,
    and the function will be lost. You should not call your variables the same
    name as your functions: it will open you up to problems. getCartProduct is
    a good name for a function, because it describes what the function does.
    It's not a good name for the return variable, because the return variables
    doesn't *get* anything: it's the function that got the data for you.

    Now... this is all a bit irrelevant at the momennt because your cfinvoke,
    as it stands, should create a new instance of the CFC, run the method,
    return the value, and destroy the CFC instance (there's a reasonable
    overhead in doing all that, hence it not being a recommended approach). So
    you shouldn't be affecting any variable within the current CFC instance
    with that.

    However if you every had this:
    <cfinvoke method="getCartProduct" returnvariable="getCartProduct">

    Then the return variable would overwrite the same-named function in the
    current CFC instance.


    Now... back to your reply to me.

    > I can browse to http://yoursite/CFC/shoppingCart.cfc, but it shows an empty
    page.

    That seems odd. You should either get an RDS login screen or the API docs
    generated by CF when one browses to a CFC file. If you're not getting
    that, something is wrong.


    > I do not have a CF mapping called CFC, pointing to the dir that has shoppingCart.cfc in it, nor did I have on the old server.

    What about a custom tag mapping? That will also assist CF finding wayward
    CFCs.


    > There are various other functions within the site that use functions from this cfc without issue,

    Are they all accessing it via the reference "CFC.shoppingCart"?

    I think if your CF template is in a directory which contains a subdirectory
    CFC with a file shoppingCart.cfc in it, then it'll work without a mapping.
    However because you're calling your CFC within itself, clearly this is not
    the case.

    Other than that, you *need* a mapping - of some description - so that CF
    can locate the file.

    Basically to reference a CFC via "CFC.shoppingCart", one of these *must* be
    true:

    - CFC/shoppingCart.cfc is within the directory of the calling template (be
    that a CFM of a CFC);
    - you have a web server mapping called "CFC", pointing to the "CFC"
    directory
    - you have a CF mapping called "CFC", pointing to the "CFC" directory
    - you have a custom tag mapping pointing to a directory which contains a
    subdirectory called "CFC".
    - there is a "CFC" subdirectory off the CF context root directory.

    You CFMX7 server config fulfilled at least one of those situations; your
    CF8 server does not.

    That's your problem. I reckon.

    --
    Adam
    BKBK
    Community Expert
    Community Expert
    May 17, 2008
    Adam,

    Thanks again. I think the service may have restarted overnight as today I get a different message. The message now reads

    Entity has incorrect type for being called as a function. The symbol you provided functionName is not the name of a function.

    This is referring to a line of code that still throws the same error at the same line if commented out. It appears to be something to do with the initial call to the cfc, not the internal call as I suspected.

    How would I go about creating a cfc mapping in CF if I do not have access to CFAdministrator? I have moved several other sites to these CF8 servers and each uses CFCs (although not as complex as this one) and they all work without issue.

    Any ideas?
    Paul

    Outside5.com,

    Pass the component path as an argument to the function. Then call the function, thus: XX("CFC.shoppingCart") .