【问题标题】:Application.cfc extending cfc in subdirectory without access to CF admin or webroot subdirectoriesApplication.cfc 在子目录中扩展 cfc,无需访问 CF admin 或 webroot 子目录
【发布时间】:2012-11-26 17:03:10
【问题描述】:

我在一个共享的 linux 服务器上,我只能访问映射到 ~/public_html 的 http://domain.com/~username/

我想在这种情况下为 ColdFusion 使用 Taffy 框架。据我所知,要使用该框架,您必须拥有一个扩展 Taffy 框架组件 taffy.core.apiApplication.cfc

https://github.com/atuttle/Taffy

https://github.com/atuttle/Taffy/wiki/Installing-Taffy

https://github.com/atuttle/Taffy/wiki/So-you-want-to:-Create-a-dead-simple-CRUD-API

我可以访问的唯一目录不是 Web 根目录的子目录,因此(据我了解)不是 ColdFusion 路径的子集。

在我的特殊情况下,我既不能访问 CFADMIN,服务器管理员也不会安装我需要在系统范围的上下文中扩展的组件,该组件已经在路径上并且可以通过全局点表示法访问。

说明说您应该将 taffy 文件夹解压缩到您的 Web 根目录,如果您不能这样做,您应该将其设为您的 api 的子文件夹。前者对我来说是不可能的,当我做后者时,我得到“找不到 ColdFusion 组件或接口taffy.core.api。”

更多详情: 我的 api 在http://domain.com/~username/api/,所以我解压了/taffy to ~/public_html/api/。如果我将 taffy/examples/api 的 Taffy 示例复制到 ~/public_html/api 以便转到 http://domain.com/~username/api/ 应该访问该示例,我会得到“找不到 ColdFusion 组件或接口 taffy.core.api”,即使下面有 taffy/core/api.cfc该目录 (~/public_html/api)。

在这台服务器上,我成功地制作了 cfc,它使用 <cfset THIS.mappings["/subdir"]= getDirectoryFromPath(getCurrentTemplatePath()) & "subdir/"><cfobject name="parentObj" component="subdir.parent"> 在另一个目录中扩展了 cfc。

我还成功制作了一个Application.cfc,它在同一目录中扩展了一个cfc

我只是没有成功创建一个可以在另一个目录中扩展 cfc 的 Application.cfc,即使它是一个子目录。

我确实尝试使用 grep 和相关工具从 Taffy 的源代码中删除“taffy.core”的每个引用,这样我就可以将所有 taffy cfc 连同 Application.cfc 一起转储到我的根目录中,这样我就可以扩展 api .cfc,但我得到了不同的错误并且没有进一步追求那个hacky解决方案。

<cfdump var=#expandPath('/mapping')# /> 输出/var/www/html/mapping

uname@domain $>ls -la /var/www/html
drwxr-xr-x  3 root   root 4096 Sep 16 00:34 .
drwxr-xr-x  7 root   root 4096 May 28  2012 ..
lrwxrwxrwx  1 root   root   19 Sep 16 00:34 cfide -> /var/www/html/CFIDE
drwxrwxr-x 10 apache root 4096 Sep 16 00:32 CFIDE

~/public_html/api/resources/successesCollection.cfc:

<cfcomponent extends="taffy.core.resource" taffy_uri="/successes">
    <cffunction name="get" access="public" output="false">
        <cfreturn representationOf('success').withStatus(200) />
    </cffunction>
</cfcomponent>

~/public_html/api/Application.cfc:

<cfcomponent extends="taffy.core.api">

<!--- doesn't work
<cfset THIS.mappings["/taffy"]= getDirectoryFromPath(getCurrentTemplatePath()) & "taffy/">
<cfset THIS.mappings["/core"]= getDirectoryFromPath(getCurrentTemplatePath()) & "taffy/core/">
--->

        <cfscript>
                this.name = hash(getCurrentTemplatePath());

                // do your onApplicationStart stuff here
                function applicationStartEvent(){}

                // do your onRequestStart stuff here
                function requestStartEvent(){}

                // this function is called after the request has been parsed and all request details are known
                function onTaffyRequest(verb, cfc, requestArguments, mimeExt){
                        // this would be a good place for you to check API key validity and other non-resource-specific validation
                        return true;
                }

                // called when taffy is initializing or when a reload is requested
                function configureTaffy(){
                        setDebugKey("debug");
                        setReloadKey("reload");
                        setReloadPassword("true");

                        // Usage of this function is entirely optional. You may omit it if you want to use the default representation class.
                        // Change this to a custom class to change the default for the entire API instead of overriding for every individual response.
                        setDefaultRepresentationClass("taffy.core.genericRepresentation");
                }
        </cfscript>
</cfcomponent>

http://domain.com/~uname/api/index.cfm/successes/ 的输出:Could not find the ColdFusion Component or Interface taffy.core.api.

将此添加到我的Application.cfc 并不能解决问题:

<cfcomponent extends="taffy.core.api">
        <cfscript>
                this.name = hash(getCurrentTemplatePath());
                this.mappings = StructNew();
                this.mappings['/taffy'] =
                expandPath('./taffy');

此外,将以下内容添加到 ~/public_html/api/Application.cfc 也不能解决问题:

<cfset this.mappings["/taffy"] =
expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & "taffy")>

查看以下命令序列,如果我忽略了某些内容,请告诉我。浏览到“http://domain/~uname/api”时,我仍然看到“找不到 ColdFusion 组件或接口 taffy.core.api”。

[uname@domain ~]$ cd ~/public_html

[uname@domain ~/public_html]$ rm -rf api

[uname@domain ~/public_html/api]$ wget -O taffy.zip https://github.com/atuttle/Taffy/zipball/master

[uname@domain ~/public_html/api]$ unzip taffy.zip

[uname@domain ~/public_html/api]$ mv atuttle-Taffy-35df54e/ taffy

[uname@domain ~/public_html/api]$ mv taffy/examples/api .

[uname@domain ~/public_html/api]$ mv taffy api/

[uname@domain ~/public_html/api]$ tree -d ~/public_html/api/
~/public_html/api/
|-- resources
`-- taffy
    |-- bonus
    |-- core
    |-- examples
    |   |-- ParentApplication
    |   |   |-- config
    |   |   |-- mixin
 ... etc

[uname@domain ~/public_html/api]$ ls -la ~/public_html/api/
total 8
drwxr-xr-x  4 uname ugroup 1024 Dec  9 11:00 .
drwxr-xr-x 10 uname web     1024 Dec  9 10:57 ..
-rw-r--r--  1 uname ugroup 1188 Dec  9 11:00 Application.cfc
-rw-r--r--  1 uname ugroup  172 Sep 20 13:04 .htaccess
-rw-r--r--  1 uname ugroup  218 Sep 20 13:04 index.cfm
drwxr-xr-x  2 uname ugroup 1024 Sep 20 13:04 resources
drwxr-xr-x  8 uname ugroup 1024 Sep 20 13:04 taffy

[uname@domain ~/public_html/api]$ ls -la ~/public_html/api/taffy/
total 15
drwxr-xr-x  8 uname ugroup 1024 Sep 20 13:04 .
drwxr-xr-x  4 uname ugroup 1024 Dec  9 11:00 ..
drwxr-xr-x  2 uname ugroup   96 Sep 20 13:04 bonus
-rw-r--r--  1 uname ugroup 4096 Sep 20 13:04 build.xml
drwxr-xr-x  2 uname ugroup 1024 Sep 20 13:04 core
drwxr-xr-x 15 uname ugroup 1024 Dec  9 10:57 examples
-rw-r--r--  1 uname ugroup   99 Sep 20 13:04 .gitignore
drwxr-xr-x  2 uname ugroup   96 Sep 20 13:04 lib
-rw-r--r--  1 uname ugroup 1356 Sep 20 13:04 LICENSE.TXT
-rw-r--r--  1 uname ugroup 2490 Sep 20 13:04 ReadMe.md
drwxr-xr-x  3 uname ugroup   96 Sep 20 13:04 snippets
drwxr-xr-x  5 uname ugroup 1024 Sep 20 13:04 tests

[uname@domain ~/public_html/api]$ ls -la ~/public_html/api/taffy/core/
total 72
drwxr-xr-x 2 uname ugroup  1024 Sep 20 13:04 .
drwxr-xr-x 8 uname ugroup  1024 Sep 20 13:04 ..
-rw-r--r-- 1 uname ugroup 42382 Sep 20 13:04 api.cfc
-rw-r--r-- 1 uname ugroup  4574 Sep 20 13:04 baseRepresentation.cfc
-rw-r--r-- 1 uname ugroup  2572 Sep 20 13:04 dashboard.cfm
-rw-r--r-- 1 uname ugroup  1756 Sep 20 13:04 dashboard.css
-rw-r--r-- 1 uname ugroup  4538 Sep 20 13:04 docs.cfm
-rw-r--r-- 1 uname ugroup  3030 Sep 20 13:04 factory.cfc
-rw-r--r-- 1 uname ugroup   179 Sep 20 13:04 genericRepresentation.cfc
-rw-r--r-- 1 uname ugroup  3516 Sep 20 13:04 mocker.cfm
-rw-r--r-- 1 uname ugroup   389 Sep 20 13:04 nativeJsonRepresentation.cfc
-rw-r--r-- 1 uname ugroup  3765 Sep 20 13:04 resource.cfc

【问题讨论】:

  • 听起来你需要创建一个映射。由于您在共享主机上,您可能需要在 Application.cfc 中进行 - 即This.Mappings = {'/taffy':'/path/to/taffy'}
  • 如果我错了,请纠正我,但根据一些谷歌搜索需要在我无权访问的管理面板中检查每个应用程序设置 - 我怎么知道这是否已启用?
  • Do &lt;cfdump var=#expandPath('/mapping')# /&gt; - 这将评估映射点的位置(即工作),或者在根目录中查找文件/目录映射(即不工作)。如果没有打开,我肯定会要求主机修复它 - 想不出他们不这样做的任何原因。

标签: coldfusion taffy


【解决方案1】:

你确实有几个选择。

映射(每个应用程序或其他)

由于 Taffy 是一个开发框架,您的系统管理员/主机可能愿意将它安装在一个中心位置,供所有开发人员使用。他们可以将 Taffy 文件夹放在 Web 根目录中,或者创建一个服务器级映射到该文件夹​​的任何位置。

相对路径

应该可以从相对路径运行 Taffy。听起来这是您尝试采用的方法,但您可能没有将文件放在正确的位置。

为了使用相对路径,您需要一个类似于以下的目录结构:

~uname/api/

~uname/api/taffy/core/api.cfc        <- Framework contents
~uname/api/taffy/core/factory.cfc
~uname/api/taffy/core/dashboard.cfm
~uname/api/taffy/core/...
~uname/api/taffy/...

~uname/api/Application.cfc           <- your api code
~uname/api/index.cfm
~uname/api/resources                 <- where you put your resource CFC's

听起来你缺少“taffy”文件夹,要么将 CFC 直接放在你的 api 文件夹中,要么将“core”文件夹放在你的 api 文件夹中。

“taffy”文件夹是必需的。将您放入 Application.cfc 的 extends 属性中的点符号路径想象为文件系统路径。因为它是taffy.core.api,所以你的文件系统需要包含 taffy/core/api.cfc

【讨论】:

  • 亚当 - 感谢您的回复。我相信我已经按照您的指示进行了设置 - 请参阅我在帖子中包含的命令序列来演示这一点。还有什么我没有想到的吗?
  • 既然您使用的是 linux,那么大小写很重要。确保文件夹没有命名为“Taffy”,它应该是“taffy”。
  • 没有目录结构真的很难理解你的命令。你能解释一下~/api 是什么吗?它应该与~/public_html/api不同吗?
  • 我清理了命令并添加了 tree 和 ls -la 的输出。 ~/api 是一个误读错误;它应该是 ~/public_html/api。
  • 我似乎无法完成这项工作,即使我在 ~/public_html/api 中有 taffy/core/api.cfc,即使我有 在 ~/public_html/api/Application.cfc
【解决方案2】:

您是否尝试过使用相对路径代理,正如 Ben Nadel 在这里解释的那样:http://www.bennadel.com/blog/2115-Extending-The-Application-cfc-ColdFusion-Framework-Component-With-A-Relative-Path-Proxy.htm

这个想法是您的 application.cfc 将扩展驻留在同一目录中的本地代理 (rootProxy.cfc)。然后该代理 cfinclude 包含您感兴趣的 cfc。由于 cfinclude 采用相对路径,因此您无需担心全局点符号或映射。

【讨论】:

  • 基本上app/Application.cfc扩展了TaffyProxy,api/TaffyProxy.cfc只有一行:
猜你喜欢
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 2016-06-21
  • 2011-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多