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.
if you have the Application.cfc in the root of your folder structure, you could use something like this:
<cfset this.mappings["/local"] = getDirectoryFromPath(getCurrentTemplatePath()) />
and then access it through "local.bin.myComponent"