| Georgetown University | Home | A-Z Index | Contents | Directories | Search |
UIS
» Web development »
Web
application development » ColdFusion
» FuseBoxCoding your application |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In the previous section, planning your application, we arrived at an outline of objects and actions. In this section, we will turn that outline into a structure of directories and files for CFML code. Directory and file structure It is always good practice to separate different ColdFusion applications into different directories. FuseBox applications follow these general rules for organizing code within the main application directory:
The FuseBox methodology includes conventions for naming action files (also called fuses). These are optional but are strongly recommended to make it easier for other developers to "read" your application. The following conventions are the most common:
An ideal action file -- or fuse -- is short and carries out a quite specific task. As you work from your outline to create a framework of directories and files, you may find yourself adding actions that were not in your original outline, or even removing actions. For example:
Returning to our example from the prior section, our directories and files might look like this:
As you apply the FuseBox methodology to multiple applications and objects, you will find that the lists of files in object directories start to look remarkably similar. In fact, it is possible to create application templates and literally cut and paste code for common actions. The function of object index.cfm files So far FuseBox is just a consistent way of arranging directories and files corresponding to objects and actions. Now we will consider how FuseBox helps control the flow of program control through the files in a ColdFusion application.
The index.cfm file for each object in a FuseBox application controls the application's use of all the actions associated with the object. The action files for an object are never linked to directly. Instead, you specify the object's index.cfm file, an Action parameter for the action you need, and any other necessary parameters. Each object's index.cfm file is made up mostly of a CFSWITCH statement that considers the specified Action parameter and routes the program to the right code for the action. Here is what part of the CFSWITCH statement in the index.cfm file for the staff object in our example might look like:
As you can see, the index.cfm file uses CFINCLUDE to include the code of the relevant action file. In this example, if a user linked to "index.cfm?Action=List" the ColdFusion application server would process the content of the index.cfm file, including the content of the dsp_List.cfm file. If no action is specified, the object responds with a default action. For a more complete example, see the index.cfm file in our first application template. Centralizing program flow in the object index.cfm files conveys several important benefits:
Typically it is desirable to prevent users from accessing parts of an application without getting there as you intended. For this reason, most FuseBox applications include in their Application.cfm file a piece of code such as this one, which effectively prevents a user from accessing any action file on its own (without the object's index.cfm):
At this point you may wish to move on to our application templates site, where you will find working examples of FuseBox applications at different levels of complexity. Or you read on to find out what the FuseBox methodology has to say about documenting your application. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| © Copyright 2001, Georgetown University |