2009-06-24 110 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映射只是一切,但是这方面的工作。有点令人失望,因为我喜欢在管理员中尽可能少的定义。我喜欢只是压缩应用程序并将其部署到任何地方。