使用<cfinclude> with this.mapping </cfinclude>

时间:2012-03-13 15:30:55

标签: coldfusion mapping coldfusion-9 application.cfc

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

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

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

1 个答案:

答案 0 :(得分:7)

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

'images'FoldFusion映射仅适用于ColdFusion - 例如,在创建对象时,您可以使用createObject(“component”,“images.image”)(当然假设您有一个名为Image的CFC)那种药物。