Friday, October 11, 2013

Setting up a ColdFusion site in Dreamweaver CS5

-----

 Requirements

User level

Beginning

Required products

Sample files

Setting up a ColdFusion site in Dreamweaver CS5

Once you have installed ColdFusion, you're ready to start developing ColdFusion pages and applications in Dreamweaver. In order to display your pages in Live view or Preview In Browser, the dynamic code needs to be processed by the ColdFusion server. This means storing your pages inside the server's document root. If you followed the instructions in the preceding pages, the document root will be at the following location:
  • Windows: C:\ColdFusion9\wwwroot
  • Mac OS X: Applications/ColdFusion9/wwwroot
Note: Strictly speaking, you can store your ColdFusion files anywhere on your computer, but they need to be copied to the ColdFusion server whenever you view them. So, it's common practice to store them inside the document root in the first place. This avoids cluttering your hard disk with duplicate files.
Instead of accessing the files directly, you need to use a URL. The URL for the ColdFusion document root ishttp://localhost:8500/ or http://127.0.0.1:8500/. Both represent the same place: localhost is an alias for 127.0.0.1, the loopback IP address meaning this computer. The :8500 indicates the port used by a ColdFusion development server.
If you locate all your files in the wwwroot folder, you can create only one site. So, it's usually more efficient to develop your ColdFusion sites in a subfolder of wwwroot. You add the name of the subfolder to the end of the URL in the same way as you would for a subfolder in a live website. For example, if you create a site in a subfolder called cftest, the URL becomeshttp://localhost:8500/cftest/.
  1. Download the sample files for this article (the link is on the first page), and unzip them.
  2. Create a new folder called cftest in the ColdFusion server document root. In Windows, the folder will beC:\ColdFusion9\wwwroot\cftest. On a Mac, it will be Applications/ColdFusion9/wwwroot/cftest.
  3. Copy the sample files into this folder. You should have three subfolders called _notesassets, and data, and a file calledcomments.cfm (see Figure 15).
Figure 15. Place the sample files in a subfolder of the ColdFusion server's document root.
  1. In Dreamweaver CS5, select Site > New Site.
  2. In the Site Setup dialog box, type ColdFusion Test as the Site Name.
  3. Click the Browse for Folder icon to the right of the Local Site Folder, navigate to the cftest folder in the ColdFusion server document root, and select it. On Windows, Local Site Folder should displayC:\ColdFusion9\wwwroot\cftest\ (see Figure 16). On a Mac, it should be /Applications/ColdFusion9/wwwroot/cftest.
Figure 16. Create the basic site definition in Dreamweaver CS5.
  1. You don't need to define the testing server for a site until you're ready to start testing, so you could click Save at this point. However, since you're going to test the site immediately, select Servers from the list on the left of the Site Setup dialog box.
  2. Click the plus (+) button at the bottom left of the Servers panel to add a new server.
  3. With the Basic button selected at the top of the dialog box that opens, select Local/Network from the list of Connect Using options. Although there is also an RDS option, using Local/Network is quicker and easier when working with a local development server.
  4. Give the server a name, such as Local Testing.
  5. Set the Server Folder text field to the same value as you used for Local Site Folder. On Windows, this isC:\ColdFusion9\wwwroot\cftest\, and on a Mac, /Applications/ColdFusion9/wwwroot/cftest.
  6. Type the URL for the testing server in the Web URL text field (see Figure 17). On both Windows and Mac, this ishttp://localhost:8500/cftest/.
Figure 17. Specify the basic settings for the testing server.
  1. Click Advanced at the top of the dialog box. For the Server Model select ColdFusion (see Figure 18), and click Save.
Figure 18. Set the Server Model option to ColdFusion.
  1. Make sure the Remote check box is deselected and the Testing check box is selected (see Figure 19), and click Save to complete the site and testing server setup.
Figure 19. Make sure the Testing check box is selected.
The Dreamweaver site is now defined and the sample files installed. The next step is to connect to the sample database included in the sample files.

Connecting to a database

This section describes how to create a connection to a sample database. The sample files you copied in the previous section include an embedded Derby database. Derby is supported in all operating systems that ColdFusion supports and is therefore a great solution for cross-platform development.
When developing a ColdFusion web application in Dreamweaver, you connect to a database by selecting a ColdFusion data source defined in ColdFusion Administrator, the server's management console. A ColdFusion data source is a type of shortcut to a database. Dreamweaver uses the data source to create a connection to the database.
For information on connecting to other database systems, see Database connections for ColdFusion developers (link to DW CS5 help page) in the Dreamweaver online help.

Create a ColdFusion data source

To create a ColdFusion data source, follow these steps:
  1. First, you need a ColdFusion page open in the Dreamweaver Document window. Although the sample files containcomments.cfm, it contains a reference to a data source that doesn't yet exist. So select File > New, and create a blank ColdFusion page. There's no need to save it, because it will be deleted once the data source has been established.
  2. Choose Window > Databases to open the Databases panel (or press Ctrl+Shift+F10 on Windows or Shift+Cmd+F10 on Mac OS X). There should be check marks against the first three items. The next stage is to specify the RDS login information for the ColdFusion server. Click the link in item 4 (see Figure 20).
Figure 20. Set the RDS login information for the ColdFusion server.
  1. In the dialog box that opens, type admin as the User Name.
  2. Type the RDS password you created for the ColdFusion administrator as the Password, and click OK.
  3. Click the data source link in item 5. If it's no longer visible in the Databases panel, switch to the Bindings panel, and click the data source link there. This launches the ColdFusion Administrator in your default browser. Enter your ColdFusion administrator password if necessary.
  4. The ColdFusion Administrator should open automatically in the Data Sources screen. If it doesn't, select the Data Sources link in the left sidebar.
  5. In the Data Source Name text box, type connTownsend (no spaces).
  6. Select Apache Derby Embedded from the Driver list.
  7. Click Add.
  8. Click the Browse Server button next to the Database File text box, and then locate and select the conntownsend2 folder.
  9. The folder should be located in the following folder:
  10. \ColdFusion9\wwwroot\cftest\data\conntownsend2
  11. Ensure that Create Database is not selected.
  1. Click Submit to accept your choices.
  2. In Dreamweaver, click the Refresh icon at the top right of the Databases panel (see Figure 21) to display the database connection. Expand the connTownsend branch and then the Tables branch to show three tables.
Figure 21. Click refresh and expand the tables in the Databases panel.
  1. Close the blank ColdFusion page, and open comments.cfm in the Document window.
  2. The central section contains dynamic text objects highlighted in light blue (see Figure 22).
Figure 22. The sample page contains ColdFusion dynamic text objects.
  1. Click Live View. Dreamweaver connects to the database through the ColdFusion server, and displays the results from the database (see Figure 23).
Figure 23. In Live view the page is populated with data drawn from the database.
To learn more about creating web applications with ColdFusion, visit the Getting Started page in the ColdFusion Developer Center.

No comments:

Post a Comment