Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Invoking component from cffunction

Contributor ,
May 16, 2008 May 16, 2008
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

3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 16, 2008 May 16, 2008
Thanks for your reply Adam,

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

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.

There are various other functions within the site that use functions from this cfc without issue, but it seems to fall down at the point where a cffunction uses cfinvoke to call another cffunction in the same cfcomponent.

Thanks,
Paul
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
Outside5.com wrote:
>
> There are various other functions within the site that use functions from this
> cfc without issue, but it seems to fall down at the point where a cffunction
> uses cfinvoke to call another cffunction in the same cfcomponent.
>
> Thanks,
> Paul
>

If the function in question is inside the component of which the
<cfinvoke...> tag is accessing another function; then you do not need
the component='' property. This property is used to tell the CFML
engine where to find the component. Since it is already inside the
component you want it to use you do not need to tell it to find the
component somewhere else. And since you do not have a 'cfc' mapping,
ColdFusion is looking for that location relative the the template making
the call. In this case the template is already inside the 'cfc'
directory and parameter 'cfc.shoppingCart' is looking for another 'cfc'
directory under the 'cfc' directory it is already in. I.E.
'cfc.cfc.shoppingCart.cfc' and it can not find that.

All that to say try this:

<cfinvoke method="getCartProduct" returnvariable="getCartProduct">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 16, 2008 May 16, 2008
Thanks Ian,

I see what you mean and it certainly makes sense. It doesn't however fix my problem :(

This is frustrating. I have identical files running on identical databases on two different servers, one on CF7 works and the other on CF8 does not.

Are there any differences between CF7 and CF8 that would/could affect this?

Thanks,
Paul

Error Message is:

Could not find the ColdFusion Component or Interface CFC.shoppingCart.
Ensure that the name is correct and that the component or interface exists.

Error Occurred While Processing Request
Could not find the ColdFusion Component or Interface CFC.shoppingCart.
Ensure that the name is correct and that the component or interface exists.

The error occurred in D:\site\wwwroot\cfc\shoppingCart.cfc: line 113

111 : <cfloop query="getCart">
112 : <cfinvoke method="getCartProduct" returnvariable="getCartProduct">
113 : <cfinvokeargument name="pId" value="#pId#">
114 : </cfinvoke>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 16, 2008 May 16, 2008
That's rather odd that you removed the "CFC." portion of the method in your invoke statement and you are still getting an error mentioning the "CFC.shoppingCart" address. Have you tried restarting the coldfusion service since you made the change? I find that sometimes coldfusion gets stuck on a component resource reference and won't change it until the CF application server is restarted.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 16, 2008 May 16, 2008
Very good point.

Now any idea where I would restart CF in a shared hosting environment using HELM as a control panel?

All this help is greatly appreciated.

Paul
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
Outside5.com wrote:
>
> Are there any differences between CF7 and CF8 that would/could affect this?
>

Not that I am aware of, or that I have run into in my code. Looking at
your abbreviated code sample I can see some issues that could cause
weird problems. Stuff like accessing external scopes, 'session' in your
original example. Possible composite problems masking the true location
of the error, etc.

But the entire systems would have to be analyzed to see what is or is
not a true problem.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 17, 2008 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2008 May 17, 2008
Outside5.com,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 17, 2008 May 17, 2008
Thanks BKBK,

I tried that but getting the same error. I will open another thread about this as the error has changed and it seems to be a different issue (maybe).

Paul
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 16, 2008 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2008 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 17, 2008 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2008 May 17, 2008
Could there be a name/type clash? What happens when you give the function a new name?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 17, 2008 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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 17, 2008 May 17, 2008
LATEST
> 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?

Definitely not something new.

I suspect something else has changed in the environment that you either
don't know about or don't htink is relevant so didn't tell us.

Still: it works now, which is the main thing :-)

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2008 May 17, 2008
All's well that ends well.




Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources