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.
A ColdFusion component is basically a collection of functions that relate to a given entity, like for example, a customer. You could create a ColdFusion Component that is responsible for the programming logic regarding your customer records. For example, you could create one ColdFusion component called customer.
You can invoke CFC methods directly by specifying the CFC in a URL, or by using HTML and CFML form tags.
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");
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With