如果我有一个如下所示的文件夹结构:
/
/bin/myComponent.cfc
/reports/index.cfm
Run Code Online (Sandbox Code Playgroud)
如何从index.cfm启动myComponent.cfc?
myService = createObject("component", "bin.myComponent");
Run Code Online (Sandbox Code Playgroud)
使用点语法,我知道如何进入更深层次的文件夹,但如何进入文件夹,然后进入另一个文件夹?使用斜杠语法,它将是这样的:
../bin/myComponent.cfc
Run Code Online (Sandbox Code Playgroud)
但是createObject()不能那样工作.我想保留一个相对路径,以便我可以将此文件夹移动到另一台服务器而不会破坏路径.
想法?谢谢!
编辑:
我的示例没有为您提供的广告素材答案显示足够深的文件夹结构.这是我应该做的:
/[my project folder]/
/[my project folder]/bin/myComponent.cfc
/[my project folder]/reports/index.cfm
Run Code Online (Sandbox Code Playgroud)
我的基本问题是,当使用从index.cfm到myComponent.cfc的createObject("component","dot path")时,是否可以使用UP目录.如果[my project folder]的名称在所有安装中都不是静态的该项目.
如果答案是否定的,那么我只需要弄清楚最佳实践是什么,无论是映射还是应用程序设置.
小智 17
如果您在文件夹结构的根目录中有Application.cfc,则可以使用以下内容:
<cfset this.mappings["/local"] = getDirectoryFromPath(getCurrentTemplatePath()) />
Run Code Online (Sandbox Code Playgroud)
然后通过"local.bin.myComponent"访问它
Nic*_*unt 16
我们使用cf管理员中的映射来处理这个问题.通常所有组件都位于www根目录之上的一个目录中.在您的情况下,您可以添加映射到/,这将允许您执行:
myService = createObject("component", "mymapping.bin.myComponent");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14063 次 |
| 最近记录: |