Ben Nadel posted about using a ColdFusion custom tag to act as a proxy to invoke a CFC. The benefit of this technique is that you're able to invoke CFCs from outside the webroot without creating any server-level mappings.
There have been several solutions to invoking CFCs without using a mapping—including the component() UDF solution I've blogged in the past. The reason I think most people hesitate to use component() UDF—which allows for using relative paths—is that it uses underlying Java calls which are not supported. Now this UDF works in ColdFusion versions 6 through 8, I understand why people might be hesitant to use it.
The technique Ben blogs about should work with all Java-based versions of ColdFusion and doesn't require any hacks, so it should be future-proof.
Taking the technique he posted I step further (which I posted as a comment) you could even tag advantage of ColdFusion 8's ability to define Application-level custom tag mappings and change the structure to something like:
The /root/cfc/ folder would be the folder where you'd place your root CFC folder (which in this case I called "com".) To actually make all this easy to use, you just need to add the custom tag pathings to your Application.cfc:
this.customTagPaths = getDirectoryFromPath(getCurrentTemplatePath()) & "..\cfc\," & getDirectoryFromPath(getCurrentTemplatePath()) & "..\tags\;
This will set up both the /cfc/ and /tags/ folder as paths to search for custom tags. Now all you'd need to do to create a CFC is to call <cf_createCFC /> from within any template to invoke your CFC.
You could take things a step further and even create a UDF called createCFC() which would simply call the <cf_createCFC /> tag.
It's a pretty clever technique which allow you to use CFCs without having to set up server-level mappings—which can cause problems on shared servers. Plus, I'm always looking to simplify the configurations of my applications. The closer I can get my applications to just copy and run, the happier I am.
Comments for this entry have been disabled.