
203
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
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
method in a child component invoked the
getPaid
method of its parent component.
The child’s
getPaid
method then used the salary returned by the parent’s
getPaid
method to calculate the
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"
attribute in a method’s cffunction tag, access to the 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 “
Using access security
” on
page 204.
Invoke a packaged component method with the cfinvoke tag
1
In your web root directory, create a directory named
appResources
.
2
In the appResources directory, create a directory named
components
.
3
Copy the tellTime2.cfc file you created in “
Invoking methods of a CFC instance
” on page 191 and the
getUTCTime.cfm file that you created in “
Placing executable code in a separate file
” on page 181 to the components
directory.
4
Create the timeDisplay.cfm file with the following content and save it in your web root directory:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...