coldfusioncfc

In Coldfusion, how do I init a component that is located above the current path folder?


If I have a folder structure that looks like this:

/
/bin/myComponent.cfc
/reports/index.cfm

How do I initiate myComponent.cfc from index.cfm?

myService = createObject("component", "bin.myComponent");

Using the dot syntax, I know how to go to deeper folders, but how to do I go up a folder, and down into the other folder? Using slash syntax it would be something like this:

../bin/myComponent.cfc

But createObject() doesn't work that way. I'd like to keep a relative path so that I can move this folder to another server without breaking the paths.

Ideas? Thanks!

EDIT:

My example didn't display a deep enough folder structure for the creative answers that you all have provided. Here's what I should have done:

/[my project folder]/
/[my project folder]/bin/myComponent.cfc
/[my project folder]/reports/index.cfm

My basic question was if it was possible to go UP a directory when using createObject("component","dot path") from index.cfm to myComponent.cfc IF the name of [my project folder] is not static across all installs of the project.

If the answer is NO, then I'll just need to figure out what the best practice is, whether it's a mapping or an application setting.


Solution

  • We handle this using a mapping in the cf administrator. Usually all of the components go in one directory which is above the www root. In your case you could add a mapping to / which would allow you to do:

    myService = createObject("component", "mymapping.bin.myComponent");