I have the following directory structure:
| SITES_FOLDER
|___ WEBSITE1
|___ WEBSITE_CFC
|___ CFC_DIR
WEBSITE1 contains an Application.cfc and some pages. Then I have a component ShoppingCart.cfc inside the WEBSITE_CFC directory that is instantiated on session start using this code:
createObject("component","WEBSITE_CFC.ShoppingCart").Init() />
This works.
Now I move ShoppingCart.cfc to the CFC_DIR directory and change my instantiate code to:
createObject("component","CFC_DIR.ShoppingCart").Init() />
Obviously this does not work because ColdFusion searches for a "CFC_DIR" directory under the root directory "WEBSITE1" and doesn't find it.
I thought this problem would be solved by using mappings so I go to the CFIDE administrator. Server Settings > Mappings.
Logical path: "CFC_DIR"
Directory path: "C:\some\folders\SITES_FOLDER\CFC_DIR"
No luck. So then I tried in Application.cfc:
<cfset THIS.mappings["/CFC_DIR"] = "C:\some\folders\SITES_FOLDER\CFC_DIR" />
This did not work either!
EDIT:
Maybe I understand: if I try to create the CFC from a cfm template, it works.
The error comes up when I try to create it inside the OnSessionStart Application.cfc's method:
Ensure that the name is correct and that the component or interface exists. Message Could not find the ColdFusion component or interface C:\some\folders\SITES_FOLDER\WEBSITE1|WEBSITE_CFC\ShoppingCart.cfc.
In other words, it keeps looking for it in the wrong dir.
WHY?
If you're changing the file to /CFC_DIR but it's still using /WEBSITE_CFC it sounds like the cache needs clearing.
Clearing the cache can be done manually in the ColdFusion Administrator. After login, the third item in "Server Settings" is "Caching". Scroll to the bottom of the page for buttons to clear the cache.
For development purposes you may want to consider disabling the various caching options on this page entirely - they can be useful for performance improvement on live servers, but are generally an unnecessary hindrance on your development machine.
If you have an automated deployment, you don't want to have to login to the CF Admin on remote servers and press buttons. Fortunately, you can also clear the cache programmatically:
<cfscript>
createObject("Component", "cfide.adminapi.administrator")
.login("**replace with admin password**");
RuntimeService = createObject("component", "cfide.adminapi.runtime");
// Clear whole cache:
RuntimeService.clearTrustedCache();
// Clear cache for individual files:
RuntimeService.clearTrustedCache("/path/to/file1.cfm,/path/to/file2.cfm");
// Clear component cache:
RuntimeService.clearComponentCache();
</cfscript>
(Code adapted from Charlie's blog entry.)
The API for the Admin Runtime component can be found at http://www.cfexecute.com/admin-api-documentation/runtime-cfc/