vol*_*one 2 coldfusion coldfusion-10
使用:CF10和IIS7.5
我的网站中有一个名为"预订"的部分.它的位置如下:
c:\inetpub\wwwroot\mysite\bookings
Run Code Online (Sandbox Code Playgroud)
在这个文件夹中将是子文件夹,最终是网页本身.下面是一个例子:
c:\inetpub\wwwroot\mysite\bookings\holidays\new.cfm
c:\inetpub\wwwroot\mysite\bookings\carhire\edit.cfm
Run Code Online (Sandbox Code Playgroud)
我<cfinclude>
在每个网页中包含(使用)另一个页面,根据调用它的页面显示不同的链接.我想知道的是"预订"文件夹之前的目录.像这样的东西(伪代码):
<cfset whereAmI = #GetDirectoryFromPath(GetBaseTemplatePath())#>
<cfif #whereAmI# EQ "C:\inetpub\wwwroot\mysite\bookings">
<h1>Booking Section Links</h1>
</cfif>
Run Code Online (Sandbox Code Playgroud)
上述代码仅在用户访问bookings/index.cfm
"bookings"文件夹的页面时有效.但如果他们转到bookings/holidays/new.cfm
页面,它现在位于holidays
文件夹中,因此<h1>
内容不会出现.我真的只想检查预订文件夹中的任何页面,即使它位于预订文件夹中的子文件夹中.有点像SQL,我可以IF #GetDirectoryFromPath(GetBaseTemplatePath())# LIKE 'c:\inetpub\wwwroot\mysite\bookings%'
这么说它最后有一个通配符.
我知道这个问题会激怒MVC框架的拥护者,但请原谅我!
这是一种快速,简单的方法来解决您的问题(可能无法在系统扩展时工作 - 但应该让您从正确的道路开始).
<cfset whereAmI = GetDirectoryFromPath(GetBaseTemplatePath())>
<cfif whereAmI CONTAINS "C:\inetpub\wwwroot\mysite\bookings">
<h1>Booking Section Links</h1>
</cfif>
Run Code Online (Sandbox Code Playgroud)
注意,我#
从里面删除了 你cfset
,cfif
你不需要它们.
你甚至可以缩小路径,只使用'mysite\bookings'.
理想情况下,这应该包含在一个函数中,以便您可以轻松地将不同的路径传递给它,以确定您是否在给定页面上.或者,甚至可以确定onRequestStart
Application.cfc中的"父"文件夹,并将其设置为请求范围变量.
如果您在基于*nix的系统上运行代码,则需要进行调整.