MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 247

Developing coldfusion mx applications
Table of Contents

Advertisement

Using component packages
Components stored in the same directory are members of a component package. Component
packages help prevent naming conflicts and facilitate easy component deployment. For example:
ColdFusion searches the current directory first for a CFC. If you put two components in a
single directory as a package, and one component refers to the other with only the component
name, not a qualified path, ColdFusion always searches the package directory first for the
component. As a result, if you structure each application's components into a package, your
applications can use the same component names without sharing the component code.
If you use the
access="package"
method is limited to components in the same package. Components in other packages cannot
use this method, even if they specify it with a fully qualified component name. For more
information on access security, see
To invoke a packaged component method using the cfinvoke tag:
In your web root directory, create a directory named appResources.
1
In the appResources directory, create a directory named components.
2
Move the tellTime.cfc and getUTCTime.cfm files that you created in the
3
methods"
section to the components directory.
Create a ColdFusion page with the following content and save it in your web root as
4
timeDisplay.cfm:
<h3>Time Display Page</h3>
<b>Server's Local Time:</b>
<cfinvoke component="appResources.components.tellTime"
method="getLocalTime"><br>
<b>Calculated UTC Time:</b>
<cfinvoke component="appResources.components.tellTime"
method="getUTCTime">
You use dot syntax to navigate directory structures. Place the directory name before the
component name.
The following example shows a CFScript invocation:
<cfscript>
helloCFC = createObject("component", "appResources.components.catQuery");
helloCFC.getSaleItems();
</cfscript>
The following example shows a URL invocation:
http://localhost/appResources/components/catQuery.cfc?method=getSalesItems
Using CFCs in persistent scopes
You can put a CFC instance in the Session or Application scope. This way, the component
properties continue to exist while the scope persists,. For example, you might want to use a CFC
for a shopping cart application, where the shopping cart contents must persist for the length of
the user's session. If you put the shopping cart CFC in the Session scope, you can use component
properties to store the cart contents. For example, the following line creates an instance of the
shoppingCart component in the Session scope.
<cfobject name="Session.myShoppingCart" component="shoppingCart">
attribute in a method's
"Using access security" on page
tag, access to the
cffunction
248.
"Defining component
Building ColdFusion components
247

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents