2009-06-24 114 views
2

自定義標籤是否可用於映射? 我試圖不必將CustomTags文件夾作爲相對地址。自定義標籤和cfimport

我已經試過:

<cfset this.mappings["/CT"] = Expandpath("/myProjects/Project1/CustomTags")> 

內的Application.cfc,然後

<cfimport prefix="tag" taglib="/CT"> 

我的網頁裏面,但事實並非如此。

它說:

無法導入由/ CT指定的標籤庫。 遇到以下錯誤:C:\ Inetpub \ wwwroot \ CT。確保你已經指定了一個有效的標籤庫。

回答

1

該文檔說它可以在Administrator ColdFusion映射頁面中指定的目錄中工作。您是否嘗試過在ColdFusion管理員中設置映射以查看該映射是否首先運行?如果可行,但在application.cfc中爲每個應用程序設置的this.mappings不起作用,那麼可能它是一個錯誤?!?

編輯: 我測試了亞當的建議,使用expandPath()函數,但是這也不起作用,因爲標籤庫屬性必須包含一個恆定值。它不能包含變量或函數。除非您使用ColdFusion管理器中的映射集,否則它不起作用。我使用這個application.cfc嘗試了下面的測試。

<cfcomponent> 

    <cfset this.name = "TestApp" /> 
    <cfset this.loginStorage = "session" /> 
    <cfset this.sessionManagement = true /> 
    <cfset this.setClientCookies = true /> 
    <cfset this.setDomainCookies = false /> 
    <cfset this.sessionTimeOut = CreateTimeSpan(0,12,0,0) /> 
    <cfset this.applicationTimeOut = CreateTimeSpan(1,0,0,0) /> 
    <cfset this.mappings['/CT'] = "C:\apache\htdocs\myProjects\Project1\CustomTags"/> 

</cfcomponent> 

而這在一個ColdFusion模板:

<cfimport prefix="tag" taglib="#expandpath('/CT')#"> 

拋出錯誤:

This expression must have a constant value.

<cfset CT = expandpath('/CT')/> 
<cfimport prefix="tag" taglib="#CT#"> 

拋出錯誤:

This expression must have a constant value.

1

我敢肯定,你不能對cfimport標籤做任何事情。我認爲你必須使用相對路徑,並且你必須在每個頁面上手動包含它。 (將它放在application.cfc文件的某處或其他地方)

+0

This.mappings需要位於Application.cfc的頂部,並且cfimport需要位於頁面上。 我已經用cfinclude成功地使用了This.mappings,但沒有使用cfimport。 – 2009-06-24 15:17:01

1

我很確定expandPath尊重CF映射。你有沒有嘗試過這樣的事情?

<cfset this.mappings["/CT"] = Expandpath("/myProjects/Project1/CustomTags")> 

<cfimport prefix="tag" taglib="#expandPath('/CT')#"> 
2

相反的是傑森報道 - 我有CFIMPORT工作得很好瓦特/每個應用程序映射VS之一CFAdmin全局設置。 CFIMPORT對於映射來說很麻煩(比如你不能在相對路徑中使用變量,也不能使用擴展路徑) - 但你應該能夠做你正在請求的沒有問題的東西。

您是否在CFAdmin中選中了「啓用每個應用程序設置」|設置允許你使用this.mappings?你正在運行什麼版本的CF?我使用CF8與此代碼,沒有任何問題:

應用CFC(功能之外,但瓦特/組件):

this.rootPath = getDirectoryFromPath(getCurrentTemplatePath()); // this assures path of application.cfc is used to determine path, likely equivalent to expandPath("/") 
structInsert(this.mappings, '/vp', this.rootPath); 

在CFC(功能之外,但瓦特/組件):

<cfimport prefix="loader" taglib="/vp/view/_loader/"> 

然後,我可以在CFC中使用,它按預期工作。

+0

它沒有工作,但沒關係。 我只會使用相對尋址來引用我的自定義標籤。 application.cfc stmts工作,但cfimport失敗。 – 2009-08-03 18:18:46

+0

確保在使用每個應用程序映射時,在CFAdmin中沒有任何同名的全局映射。在上面的例子中,確保從CFAdmin Mappings中刪除「/ vp」,以確保CF使用每個應用程序與全局映射。 – mujimu 2009-08-17 17:22:42

1

我已確認它...您不能使用通過application.cfc中的「this.mappings」結構創建的映射。

從Adobe的文檔(ColdFusion的9):

The path must be relative to the web root (and start with /), the current page location, or a directory specified in the Administrator ColdFusion mappings page.

CFImport Documentation for CF 9

不知道爲什麼的Application.cfc映射只是一切,但是這方面的工作。有點令人失望,因爲我喜歡在管理員中儘可能少的定義。我喜歡只是壓縮應用程序並將其部署到任何地方。