Is there a way to specify the component path in the tag?
I am using ColdFusion Components for my application. My application has several folders, however, and each time I want a CFC to work, I have to save it in the same directory as those files that need access. This results in my creating of several CFC files that are identical.
Is there a way to store my CFCs in one directory and make it work across my site?
Application component written in CFML (ColdFusion Markup Language), a programming language used to build Internet applications; contains data and functions, called methods, for an application module; defined within the file using a <cfcomponent> tag.
A ColdFusion component (CFC) is a file saved with the extension . cfc. A CFC can contain data and functions. Within a CFC, data is referred to as properties. Although you use the cffunction tag to define functions within a CFC, they are typically referred to as methods instead of functions.
As others have noted, you can do interesting things with mappings and functions that locate the root of your application, but at the heart of your question is general path specification.
I would suggest you read the portion of the Using ColdFusion Components documentation titled Specifying the CFC location.
Essentially, what it says is that if your application lives at http://example.com/myApp/ and you have a page at http://example.com/myApp/foo/bar/fubar.cfm that wants to use the component at:
/myApp/foo/components/library/fubar.cfc
then fubar.cfm should do something like this:
<cfset fubar=createObject("component", "myApp.foo.components.library.fubar") />
You take the path of the file and replace slashes with dots (aka "dot notation"), and also drop the ".cfc" from the file name of the component you want to load.
In addition, you can use named mappings (as Aaron described), so if you create a mapping called /components
that points to /myApp/foo/components/
then your createObject call would look like this:
<cfset fubar = createObject("component", "components.library.fubar") />
The same dot-notation paths can be used in <cfinvoke />
, as part of the component
attribute:
<cfinvoke component="components.library.fubar" ... />
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