Coldfusion mx Tips extract 2 1/6 page _coldfusion

Source: Internet
Author: User
Set your root directory

Author: Kyle 2/16/03

Content:

Set your root directory
Web site developers have always had to spin around the topic of relative path vs. absolute path. In a ColdFusion environment, you can use Cfinclude labels on multiple different pages, but since we're going to use the Cfinclude syntax in which directory, it's often a lot of trouble to use relative paths in cfinclude labels.

For example, one of the included menus may have a link to the home page of the site, as follows:

<a href= "index.cfm" >home page</a>
Any file that is under the root directory of the Web site will not have a problem introducing this include file. But if you introduce the menu file to a file in a directory, the hyperlink will fail, or at least link to the wrong page. That's when you actually want this hyperlink to be written like this:

<a href= ". /index.cfm ">home page</a>
There are two ways to overcome this problem. One is to use the absolute path directly inside the hyperlink. To use this approach, you must preset a path correspondence (mapping) in the ColdFusion. You can establish these relationships in the "Path Correspondence (mappings)" Block of the ColdFusion Administrator (ColdFusion). Once you have established the path correspondence, you can write a hyperlink to the homepage of the site as follows:

<a href= "/mymapping/index.cfm>home page</a>
If you use an absolute path, the hyperlinks in that file will always remain in effect, no matter where you introduce the file. I usually use a name called application. RootDir Application variables to store this path corresponding to the setting, and apply this variable directly inside the hyperlink. Using this approach, if I really need to modify the directory structure or the corresponding name of the path, then I just need to modify the value of such a variable.

<cfset application. RootDir = "/mymapping" >
If you apply this variable, your hyperlink will look like this:

<a href= "#APPLICATION. Rootdir#/index.cfm ">
To create such a variable at the beginning of each page, you can apply the value of the variable to the other part of the page. The inclusion of the file works as if the contents of the file are actually written to the original page, so if file a introduces file B, then in file B we can refer directly to the value of the variable in file a:

<!---set RootDir variable value on each page--->
<cfset RootDir = ". /">
<!---refer to the value of the RootDir variable in the introduced page (as long as you are sure that the variable is actually defined, the error message will appear when you introduce the file)--->
<a href= "#RootDir #news/newspage.cfm" ></code>
Current 1/6 page 123456 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.