DP Libraries: Using DP_Paths
The DP_Paths component is one of the simpler but more useful utility components. Essentially it's just an abstraction of the exiting path-related functions available in CFML. It allows you to define the home directory of an application and generate the many directory paths needed when constructing an application. It's very useful in constructing portable elements (for example header and footer files) and applications as the paths it returns are generated based on current file locations.
First let's define some of the terms used in this documentation.
- Web Root: This is the root of the web server as defined by the HTTP server. In our examples we'll assume that this root is "C:\WebRoot".
- Application Root: This is the root of the current application (which may be the same as the web root). For example if the application was contained in the folder "MyApp" and installed on the web root above the Application root would be "C:\WebRoot\MyApp\".
- Application Root Offset: This is the path to the application root minus the web root. So, continuing with our example this value would be "/MyApp/". This value is used as input to the DP_Paths init() method.
In addition there are three general kinds of paths returned by this component:
- Relative from Path: These paths assume a known starting point (either the web or application root) and present the path needed to reach a specific file under it. These paths begin with a leading slash. A path from the web root to a file in the application might look like this: "/MyApp/Assets/Header/Header.cfm". These paths are especially useful for accessing resources specific to components across multiple host page locations.
- Relative to Path: These paths begin at a specified file and present the path needed to reach a known destination point (either the web or application root). The relative path to the web root from the previous file, for example, would be "../../../". These paths are especially useful for accessing general site assets from any location in an application and for accessing CFML-related materials such as Custom Tags without having to create a ColdFusion Mapping.
- Absolute Paths: These paths contain full system information including drive leter. The system path for our example Header.cfm file might be "C:\WebRoot\MyApp\Assets\Header\Header.cfm". These paths are useful in where the full-system information is needed such as log file creation with CFFILE and file management.
Next we will see several methods of instantiating and using the component.