Opomba:
Support for ColdFusion is removed in Dreamweaver CC and later.
ColdFusion component (CFC) files let you encapsulate application and business logic into self‑contained, reusable units. CFCs also provide a fast, easy way to create web services.
A CFC is a reusable software unit written in ColdFusion markup language (CFML), which makes it easy to reuse and maintain your code.
You can use Dreamweaver to work with CFCs. For information on CFC tags and syntax, see the ColdFusion documentation from within Dreamweaver (Help > Using ColdFusion).
Opomba:
You can use CFCs only with ColdFusion MX or later. CFCs are not supported in ColdFusion 5.
CFCs are meant to provide a simple yet powerful way for developers to encapsulate elements of their websites. Generally, you should use components for application or business logic. Use customs tags for presentation elements such as customized greetings, dynamic menus, and so on.
As with many other types of construction, dynamic sites can often benefit from interchangeable parts. For example, a dynamic site may run the same query repeatedly, or calculate the total price of shopping cart pages and recalculate it every time an item is added. These tasks can be handled by components. You can fix, improve, extend, and even replace a component with minimal impact to the rest of your application.
Suppose an online store calculates shipping charges based on the price of orders. For orders under $20, the shipping charge is $4; for orders between $20 and $40, the shipping charge is $6, and so on. You could insert the logic for calculating the shipping charge in both the shopping cart page and the checkout page, but that would mix HTML presentation code and CFML logic code and generally make the code difficult to maintain and reuse.
You decide to create a CFC called Pricing that has, among other things, a function called ShippingCharge. The function takes a price as an argument and returns a shipping charge. For example, if the value of the argument is 32.80, the function returns 6.
In both the shopping cart page and the checkout page, you insert a special tag to invoke the ShippingCharge function. When the page is requested, the function is invoked and a shipping charge is returned to the page.
Later, the store announces a special promotion: free shipping for all orders above $100. You make the change to the shipping rates in one place—the ShippingCharge function of the Pricing component—and all the pages using the function automatically get accurate shipping charges.
Use the Components panel (Window > Components) to view and edit ColdFusion components, and add code in the page that invokes the function when the CFM page is requested.
Opomba:
The Components panel is available only when viewing a ColdFusion page in Dreamweaver.
You can use Dreamweaver to visually define a CFC and its functions. Dreamweaver creates a .cfc file and inserts the necessary CFML tags for you.
Opomba:
Depending on the component, you may have to complete some code by hand.
-
a.In the Components section, enter the details about the component. Here is a partial list:
Name Specifies the filename of the component. The name must contain only alphanumeric characters and underscores (_). Don’t specify the .cfc file extension when entering the name.
Component Directory Specifies where the component is saved. Select the web application’s root folder (such as \Inetpub\wwwroot\myapp\) or any of its subfolders.
b.To define one or more functions for the component, select Functions from the Section list, click the Plus (+) button, and enter the details of the new function.
Ensure that you specify the type of the value returned by the function in the Return Type option.
Opomba:
If you select remote from the Access menu, the function becomes available as a web service.
Dreamweaver provides a way to visually examine the ColdFusion components (CFCs) located in your site folder or on the server as a whole. Dreamweaver reads the CFC files and displays information about them in an easy-to-navigate tree view in the Components panel.
Dreamweaver looks for the components on your testing server (see Connecting to the database in Dreamweaver). If you create CFCs or make changes to existing CFCs, make sure to upload the CFC files to the testing server so they are accurately reflected in the Components panel.
To view components located on another server, change the testing server settings.
You can view any of the following information about your CF components:
List all of the ColdFusion components defined on the server.
If you’re running ColdFusion MX 7 or later, filter the list to show only the CFCs located in your site folder.
Explore the functions and arguments of each component.
Inspect the properties of functions that serve as web services.
Opomba:
To use Dreamweaver to inspect CFCs residing in the server root while also managing your site files in a different website root, you can define two Dreamweaver sites. Set the first site to point to the server root and the second to point to the website root. Use the site pop-up menu on the Files panel to switch quickly between the two sites.
-
To display only the CFCs located in your site folder, click the Show Only Current Site’s CFCs button in the Components panel toolbar.
Opomba:
This feature is available only if you’ve defined a computer running ColdFusion MX 6 or later as a testing server for Dreamweaver.
Opomba:
If the current site is listed in a virtual folder on the remote server, the filtering does not work.
-
To list the functions of a component, click the Plus (+) button beside the component name.
To see the arguments a function takes, as well as the arguments’ type and whether they are required or optional, open the function’s branch in the tree view.
Functions that take no arguments have no Plus (+) button beside them.
To quickly view the details of an argument, a function, a component, or a package, select the item in the tree view, and click the Get Details button in the panel toolbar.
You can also right-click (Windows) or Control-click (Macintosh) the item and select Get Details from the pop‑up menu.
Details about the item are displayed in a message box.
Dreamweaver provides a streamlined way of editing the code of the ColdFusion components defined for your site. For example, you can add, change, or delete any component function without leaving Dreamweaver.
To use this feature, your development environment must be set up as follows:
ColdFusion must be running locally.
In the advanced Site Definition dialog box in Dreamweaver, the Access type specified in the Testing Server category must be Local/Network.
In the advanced Site Definition dialog box, the path of your local root folder must be the same as the path of the testing server folder (for example, c:\Inetpub\wwwroot\cf_projects\myNewApp\). You can examine and change these paths by selecting Site > Edit Sites.
The component must be stored in the local site folder or any of its subfolders on your hard disk.
Open any ColdFusion page in Dreamweaver and display the components in the Components panel. To display the components, open the Components panel (Window > Components), select CF Components from the panel’s pop‑up menu, and click the Refresh button on the panel.
Because ColdFusion is running locally, Dreamweaver displays component packages on your hard disk.
Use the following procedure to edit a component.
One way to use a component function in your web pages is to write code in the page that invokes the function when the page is requested. You can use Dreamweaver to help you write this code.
Opomba:
For other ways to use components, see the ColdFusion documentation from within Dreamweaver (Help > Using ColdFusion).
Dreamweaver can help you define a recordset (also known as a ColdFusion query) in a ColdFusion component (CFC). By defining a recordset in a CFC, you don’t need to define the recordset on each page that uses it. You define the recordset once in the CFC and use the CFC on different pages.
Opomba:
This feature is available only if you have access to a computer running ColdFusion MX 7 or later. For more information, see Enable the ColdFusion enhancements.
You can use a ColdFusion component (CFC) as a source of dynamic content for your pages if the component contains a function defining a recordset.
Opomba:
This feature is available only if you have access to a computer running ColdFusion MX 7 or later. For more information, see Enable the ColdFusion enhancements.
-
For more information, see Adding dynamic content to pages.
You can define a recordset as a source of dynamic content in Dreamweaver by using a CFC that contains a recordset definition.
1.In the Name box, enter a name for the CFC recordset.
A common practice is to add the prefix rs to recordset names to distinguish them from other object names in the code, for example: rsPressRelease.
Recordset names must contain only alphanumeric characters and underscores (_). You cannot use special characters or spaces.
2.Select a package from the ones already defined on the server.
If the package does not appear in the pop‑up menu, you can refresh the list of packages by clicking the Refresh button near the pop‑up menu.
Make sure you upload your CFCs to the testing server first. Only CFCs on the testing server are displayed.
3.Select a component from the ones defined in the currently selected package.
If the Component pop‑up menu does not contain any components, or if none of your previously created components appear in the menu, you should upload the CFC files to the testing server.
4.(Optional) To create a component, click the Create New Component button.
a.In the Name box, enter the name for the new CFC. The name must contain only alphanumeric characters and underscores (_).
b.In the Component Directory box, enter the location for your CFC, or browse to locate the folder.
Opomba:
The folder must be the relative path to the site root folder.
5.From the Function pop‑up menu, select the function that contains the recordset definition.
The Function pop‑up menu contains only the functions defined in the currently selected component. If no function appears in this pop‑up menu, or if your last changes are not reflected in the currently listed functions, check that your last changes were saved and uploaded to server.
Opomba:
The Connection and SQL boxes are read-only.
6.Edit each parameter (type, value, and default value) that must be passed as a function argument by clicking the Edit button.
a.Enter a value for the current parameter by selecting the value type from the Value pop‑up menu and entering the value in the box to the right. The value type can be a URL parameter, a form variable, a cookie, a session variable, an application variable, or an entered value.
b.Enter a default value for the parameter in the Default Value box. If no run-time value is returned, the default parameter value is used.
c.Click OK.
You cannot modify the database connection and the SQL query for the recordset. These fields are always disabled—the connection and SQL query are displayed for your information.
7.Click Test to connect to the database and create an instance of the recordset.
If the SQL statement contains page parameters, ensure that the Default Value column of the Parameters box contains valid test values before clicking Test.
If the query was executed successfully, a table displays the recordset. Each row contains a record and each column represents a field in that record.
Click OK to clear the CFC Query.