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

查看:122
本文介绍了使用相对路径扩展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都在同一目录中, / p>

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:

wwwroot\MyApp\com\MyApp\example.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天全站免登陆