使用相对路径扩展 CFC [英] Extend a CFC using a relative path

查看:22
本文介绍了使用相对路径扩展 CFC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不同的目录中扩展 CFC,我有几个选择,但不知道如何做到这一点:

I want to extend a CFC in a different directory and I have a couple of options, but can't figure out how to do this:

A) 使用动态映射(这必须是基于站点的动态映射,例如,对于实时站点,它将是 cfc.myPackage.MyCFC,但在开发站点上,它将是 myCfcRoot.myPackage.MyCFC) - 我'已经尝试将表达式放入扩展位,但显然 CF 不喜欢这样,例如:

A) Use a dynamic mapping (this will have to be dynamic based on the site, e.g. for the live site it would be cfc.myPackage.MyCFC but on a dev site it would be myCfcRoot.myPackage.MyCFC) - I've tried putting expressions into the extends bit but obviously CF doesn't like that, e.g. :

<cfcomponent name="MyComponent" extends="#config.cfcRoot#.BaseComponent">

<cfcomponent name="MyComponent" extends="#GetRealPath(../BaseComponent.cfc)#">

B) 提供 CFC 的相对路径(以某种方式)以进行扩展.

B) Provide a relative path (somehow) to the CFC to extend.

我担心我做不到,但我希望我错过了一些东西.

I fear that I can't do this, but I'm hoping that there is something I've missed.

推荐答案

Daniel 基本正确,需要映射.但是,有 3 种解决方法.

Daniel is basically correct, you need a mapping. However, there are 3 workarounds.

CFC 会选择当前路径作为相对根映射,所以如果你的 CFC 都在同一个目录中,你可以说

CFCs will pick the current path as a relative root mapping, so if your CFCs are all in the same directory, you can just say

<cfcomponent name="MyComponent" extends="Example">

或者,如果您的组件位于当前 cfc 的子目录中,您可以访问它:

Or if your components are in subdirectories from the current cfc, you can access it:

<cfcomponent name="MyComponent" extends="subdirectory.Example">  

其次,如果您在 ColdFusion 8 上运行,您可以使用如下映射结构在 application.cfc 中定义映射:

Second, if you are running on ColdFusion 8, you can define a mapping in your application.cfc using the mappings struct like this:

<cfset this.mappings["/MyApp"] = expandPath(".") />

Application.cfc有两个很好的参考,第一,Ray Camden的例子Application.cfc 这只是提供了一个很好的视图,然后是 CF8 Live Docs 应用程序设置 页面,其中有一个关于映射的部分以及一些好评.

There are two good references for Application.cfc, first, Ray Camden's example Application.cfc which just gives a nice view of what goes where, then the CF8 Live Docs application settings page, which has a section on mappings along with some good comments.

最后,您可以使用 Web 根目录的内置映射,因此如果您的应用程序位于 Web 根目录之外名为MyApp"的子目录中,您的根映射将是MyApp".假设您正确地将组件放入:

Finally, you can use the built-in mapping of your web root, so if your application is in a subdirectory named "MyApp" off the web root, your root mapping will be "MyApp". Let's say you correctly put your components in:

wwwrootMyAppcomMyAppexample.cfc

在这种情况下,到此 cfc 的映射将是:

The mapping to this cfc in this case will be:

MyApp.com.MyApp.Example

使用您的示例,您可以像这样扩展:

And using your example, you can extend like this:

<cfcomponent name="MyComponent" extends="MyApp.com.MyApp.Example">

其他任何情况,例如您的组件是否位于 Web 根目录之外,或者您不确定已完成应用程序的文件夹结构是什么,并且您需要在 CF 管理器中设置映射.

Anything else, such as if your components are outside of the web root, or if you are not sure what the folder structure of your finished application will be, and you will need to set a mapping in the CF Administrator.

这篇关于使用相对路径扩展 CFC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆