0

在我的应用程序中,我有一个页眉和页脚包含。在我的 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<cfinclude>无法在图像文件夹中找到任何内容:<li class="imagelink"><img src="/images/facebook.png"></li>

根目录中的页面没有问题。

如果我理解正确,问题与在调用包含之前没有发生映射有关,或者类似的事情......如何让映射路径在我的包含中正常工作?

4

1 回答 1

7

ColdFusion 映射完全独立于 Web 服务器的“别名”或“虚拟目录”。为了让您的代码正常工作,您需要添加一个 Web 服务器映射,在 Apache 中添加“别名”或在 IIS 中添加“虚拟目录”,命名为“images”,指向您保存图像的目录。

'images' ColdFusion 映射仅适用于 ColdFusion - 例如,在创建对象时,您可以使用 createObject("component", "images.image")(当然假设您在该目录中有一个名为 Image 的 CFC。

于 2012-03-13T15:42:56.183 回答