Adobe COLDFUSION 9 Manual page 209

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
<!--- Create the component instance. --->
<cfobject component="appResources.components.tellTime2" name="tellTimeObj">
<!--- Invoke the methods. --->
<cfinvoke component="#tellTimeObj#" method="getLocalTime"
returnvariable="localTime" >
<cfinvoke component="#tellTimeObj#" method="getUTCTime"
returnvariable="UTCTime" >
<!--- Display the results. --->
<h3>Time Display Page</h3>
<cfoutput>
Server's Local Time: #localTime#<br>
Calculated UTC Time: #UTCTime#
</cfoutput>
You use dot syntax to navigate directory structures. Place the directory name before the component name.
Browse the timeDisplay.cfm file in your browser.
5
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 place a CFC instance in the Session or Application scope. This way, the component properties continue to
exist while the scope persists. For example, if you 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 place 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
component in the Session scope:
shoppingCart
<cfobject name="Session.myShoppingCart" component="shoppingCart">
Code that manipulates persistent scope CFC properties must be locked, just as all other code that manipulates
persistent scope properties must be locked. Therefore, lock both of the following types of application code:
• Code that directly manipulates properties of a persistent scope CFC instance
• Code that calls methods of a persistent scope CFC instance that manipulate properties of the instance
If you place multiple CFC instances in a single persistent scope, you can create a named lock for each CFC instance.
For more information on locking, see
Note: Session scope CFCs cannot be serialized, so you cannot use them with clustered sessions; for example, if you want
to support session failover among servers.
Building secure ColdFusion components
To restrict access to component methods, ColdFusion components use access, role-based, or programmatic security.
Using access security
CFC access security lets you limit the code that can access the components. You specify the access to a CFC method
by specifying the cffunction
access
"Using Persistent Data and
attribute, as follows:
Last updated 8/5/2010
Locking" on page 301.
204

Advertisement

Table of Contents
loading

Table of Contents