Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store CFCs in a separate directory and make them work?

Tags:

coldfusion

cfc

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?

like image 411
Mohamad Avatar asked Mar 04 '10 13:03

Mohamad


People also ask

What is CFC extension?

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.

What is a ColdFusion component?

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.


1 Answers

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" ... />
like image 74
Adam Tuttle Avatar answered Nov 03 '22 23:11

Adam Tuttle