Adobe COLDFUSION 9 Manual page 208

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
3
Create the president.cfc file with the following content:
<cfcomponent extends="manager">
<cffunction name="getPaid" returntype="numeric">
<cfset var salary=1.5 * Super.getPaid()>
<cfreturn salary>
</cffunction>
</cfcomponent>
4
Create the payday.cfm file with the following content, and save it in the same directory as the components that you
created in the previous steps:
<cfobject name="empObj" component="employee">
<cfobject name="mgrObj" component="manager">
<cfobject name="prezObj" component="president">
<cfoutput>
<cfoutput>
An employee earns #empObj.getPaid()#.<br>
A manager earns #mgrObj.getPaid()#.<br>
The president earns #prezObj.getPaid()#.
</cfoutput>
</cfoutput>
In this example, each
getPaid
The child's
method then used the salary returned by the parent's
getPaid
appropriate amount.
Included pages can use the Super keyword.
Note: The Super keyword supports only one level of inheritance. If you use multiple levels of inheritance, you can only use
the Super keyword to access the current component's immediate parent. The example in this section illustrates handling
this limitation by invoking methods in a chain.
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 place 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"
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
page 204.
Invoke a packaged component method with the cfinvoke tag
In your web root directory, create a directory named appResources.
1
2
In the appResources directory, create a directory named components.
Copy the tellTime2.cfc file you created in
3
getUTCTime.cfm file that you created in
directory.
Create the timeDisplay.cfm file with the following content and save it in your web root directory:
4
method in a child component invoked the
attribute in a method's cffunction tag, access to the method is limited to
"Invoking methods of a CFC
"Placing executable code in a separate
Last updated 8/5/2010
method of its parent component.
getPaid
method to calculate the
getPaid
"Using access
instance" on page 191 and the
file" on page 181 to the components
203
security" on

Advertisement

Table of Contents
loading

Table of Contents