Ofe*_*all 0 mapping coldfusion application.cfc coldfusion-9
在我的应用程序中,我有一个页眉和页脚包含.在我的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>
Run Code Online (Sandbox Code Playgroud)
如果我有一个页面在这样的子目录:planning/index.cfm在<cfinclude>无法找到时,我使用以下路径的图像文件夹什么:<li class="imagelink"><img src="/images/facebook.png"></li>
根目录中的页面没有问题.
如果我理解正确,问题与在调用include之前不会发生映射有关,或类似的事情......如何让我的include中的映射路径正常工作?
ColdFusion映射与Web服务器的"别名"或"虚拟目录"完全分开.为了使您的代码能够工作,您需要添加一个Web服务器映射,Apache中的"别名"或IIS中的"虚拟目录",名为"images",指向保存图像的目录.
'images'FoldFusion映射仅适用于ColdFusion - 例如,在创建对象时,您可以使用createObject("component","images.image")(当然假设您在该行为中有一个名为Image的CFC.