Skip to main content
Inspiring
February 22, 2007
Question

path to cfc

  • February 22, 2007
  • 9 replies
  • 619 views
I have tried what the documentation says to do but can't get this to work.

How do I call CFCs that reside in a folder above the current folder?

The documentation says just to use the path but use dots instead.

So com.cfcs.mycfc But this doesn't work.
This topic has been closed for replies.

9 replies

Inspiring
February 23, 2007
Ian Skinner wrote:
> CFCs don't NEED to be either in the webroot or web accessible, unless
> they're being used as web services, do they?

if they're not in a cf mapped dir, custom tag dir, etc yes i think they do need
to be web accessible in one form or another. otherwise how would you find them?

created a CFC junk.cfc, tossed into c:\data on the server, data dir is *not* web
accessible.

<cfscript>
j=createObject("component","data.junk");
</cfscript>

"Could not find the ColdFusion Component data.junk."

if you don't use a cf mapped dir or one of its searched dirs, the CFCs need to
reside in web accessible dirs. maybe one of cf's classpaths will work but i
wouldn't let any tom, dick or harry mess around in those.
February 23, 2007
here is the solution to it

You create a mapping in the cf Administrator for the topmost folder
and then you can access anywhere using the dot operators along with the mapping name

for example
if you have a cfc at the level -- "mainfolder/subfolder/nextsubfolder/required.cfc"
you need to create a mapping
say name = com , path = physical path to "mainfolder"
Now you can access the required.cfc by creating an object as follows--
<cfset obj = createObject("component","com.subfolder.nextsubfolder.required")>

Good Luck
Inspiring
February 22, 2007
CFCs don't NEED to be either in the webroot or web accessible, unless
they're being used as web services, do they?

I don't think they NEED to, but that the webroot is one of the
automatically searched paths if one does not have a mapping.

That is my understanding anyway.
Inspiring
February 22, 2007
> someDirStructure should be off the web root &
> of course web accessible. or better yet use cf mapped dir.

CFCs don't NEED to be either in the webroot or web accessible, unless
they're being used as web services, do they?

--
Adam
BKBK
Community Expert
Community Expert
February 22, 2007
someDirStructure should be off the web root & of course web accessible.
An important consideration my example only assumes, but should have stated explicitly.

Inspiring
February 22, 2007
Azadi wrote:
> cfc is in someDirStructure/com/cfcs/mycfc.cfc

> will reference com.cfcs.mycfc still work from those locations?

no, you should provide the full path to the CFC
(someDirStructure.com.cfcs.mycfc). someDirStructure should be off the web root &
of course web accessible. or better yet use cf mapped dir.


Inspiring
February 22, 2007
i think Dinghus is asking about a case when
cfc is in someDirStructure/com/cfcs/mycfc.cfc

and createObject script is in a page in
someDirStructure/com/anotherDir/yetAnotherDir/testPage.cfm

or maybe even
someDirStructure/anotherDir/yetAnotherDir/testPage.cfm

will reference com.cfcs.mycfc still work from those locations?

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
BKBK
Community Expert
Community Expert
February 22, 2007
So com.cfcs.mycfc But this doesn't work.
Show us the directory structure of the cfm page and of the cfc. Otherwise, it's difficult to say.

Suppose your cfc is someDirStructure/com/cfcs/mycfc.cfc. Then the code

<cfset obj = createObject("component","com.cfcs.mycfc")>

will work if you put it in any of the following pages

someDirStructure/testPage.cfm
someDirStructure/com/testPage.cfm
someDirStructure/com/cfms/testPage.cfm

arbitraryDirStructure/testPage.cfm (if you have declared a "com" mapping in the Coldfusion Administrator)




Inspiring
February 22, 2007
> So com.cfcs.mycfc But this doesn't work.

"doesn't work".

Can you elaborate on that? What - exactly - happens to make you think it
doesn't work? And what - exact - code are you using which causes this?

--
Adam