Coldfusion 使用<;cfinclude>;用这个。映射

Coldfusion 使用<;cfinclude>;用这个。映射,coldfusion,mapping,coldfusion-9,application.cfc,Coldfusion,Mapping,Coldfusion 9,Application.cfc,在我的应用程序中,我有一个页眉和页脚包含。在my Application.cfc中,我设置了一个函数来命名我的应用程序并设置映射 <cfcomponent output="no"> <cfset this.name = "thesitename"> <cfset this.datasource = "thesitedatasource"> <cfset this.rootDir = getDirectoryFromPath(getCurrentTempl

在我的应用程序中,我有一个页眉和页脚包含。在my Application.cfc中,我设置了一个函数来命名我的应用程序并设置映射

<cfcomponent output="no">
<cfset this.name = "thesitename">
<cfset this.datasource = "thesitedatasource">
<cfset this.rootDir = getDirectoryFromPath(getCurrentTemplatePath()) />
<cfset this.mappings = structNew()>
<cfset this.mappings["/planning"] =  "#this.rootDir#planning/" />
<cfset this.mappings["/images"] = "#this.rootDir#images/" />
<cfset this.mappings["/includes"] = "#this.rootDir#includes/" />
<cfset this.mappings["/js"] = "#this.rootDir#js/" />
<cfset this.mappings["/portfolio"] = "#this.rootDir#portfolio/" />
</cfcomponent>

如果我在这样的子目录中有一个页面:
planning/index.cfm
当我使用以下路径时,
在图像文件夹中找不到任何内容:
  • 根目录中的页面没有问题


    如果我理解正确的话,这个问题与调用include之前没有发生映射有关,或者类似的事情。。。如何使映射路径在include中正常工作?

    ColdFusion映射与web服务器的“别名”或“虚拟目录”完全不同。为了使代码正常工作,您需要添加一个web服务器映射,即Apache中的“别名”或IIS中的“虚拟目录”,该映射名为“图像”,指向保存图像的目录


    “images”ColdFusion映射仅在ColdFusion中有效-例如,在创建对象时,可以使用createObject(“组件”、“images.image”)(当然,假设您在该目录中有一个名为CFC的映像。

    因此,基本上,没有办法使用此.mapping并使cfinclude正常工作。那么,什么类型的编码使用了
    (./images)
    syntax?您可以使用cfinclude来包含可能位于“images”目录中的ColdFusion文件,但当您指定img标记的src属性时,这意味着告诉web浏览器在哪里查找该文件,而web浏览器不知道(也不应该知道)ColdFusion映射。解决问题的简单方法是,如果在Apache上创建一个“别名”,如果在名为“images”的IIS上创建一个指向存储图像的文件夹的“虚拟目录”。然后它将“正常工作”