Railo application.cfc this.mappings 不起作用
我正在使用最新版本的railo,并且正在尝试让每个应用程序映射正常工作。这就是我正在做的:
<cfcomponent name="MyApp">
<cfset THIS.Name = "MyApp">
<cfset THIS.Mappings["/myapp"] = ExpandPath(".")>
</cfcomponent>
所以,我试图能够通过 myapp.* 映射访问此应用程序文件夹中的组件,而不是必须访问 rootapp.myapp.* (根据我的理解,此组件设置应该可以工作 但是,
我的组件无法通过此映射访问,当我对代码中的应用程序变量执行 cfdump 时,它将显示“applicationname”设置为“MyApp”,但映射没有显示任何内容
。不支持这些映射,或者我做错了什么吗?
编辑:
这就是我得到的确切错误:
invalid component definition, can't find myapp.data.MyObject
应该创建 myapp
映射,并且 MyObject
确实存在,这是我的结构。 :
/rootfolder/myapp/Application.cfc
/rootfolder/myapp/data/MyObject.cfc
/rootfolder/myapp/pages/MyPage.cfm
简而言之,“MyPage.cfm”依赖于映射来轻松访问“MyObject”组件,应该加载 Application.cfc,因为 cfml 处理器应该开始向上移动目录,直到找到一个。
i am using the latest version of railo, and am trying to get the per-application mappings to work. this is what i am doing:
<cfcomponent name="MyApp">
<cfset THIS.Name = "MyApp">
<cfset THIS.Mappings["/myapp"] = ExpandPath(".")>
</cfcomponent>
so, i am trying to be able to access components within this application folder through a myapp.* mappings rather than having to to rootapp.myapp.* (from what i understand, this component setup should then work.
however, my components cannot be accessed by this mapping, and when i do a cfdump on the application variable in my code, it will show that the "applicationname" is set to "MyApp", but nothing shows for the mappings.
does railo not support these mappings, or am i doing something wrong?
EDIT:
this is the exact error that i am getting:
invalid component definition, can't find myapp.data.MyObject
the myapp
mapping should have been made, and the MyObject
does exist. here is my structure:
/rootfolder/myapp/Application.cfc
/rootfolder/myapp/data/MyObject.cfc
/rootfolder/myapp/pages/MyPage.cfm
in short, "MyPage.cfm" relies on the mapping to easily access the "MyObject" component. the Application.cfc should be loaded as the cfml processor should start moving up directories until it finds one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的语法没问题,我刚刚对目录树深处的应用程序做了同样的事情,它工作得很好。
确切的错误是什么? “组件定义无效,找不到 myapp.xyz”?
你的cfm和cfc在同一个目录下吗? (这基本上就是你想要做的)
通过转储应用程序范围,您将看不到此信息。唯一的选择是像往常一样使用 Application.cfc。
编辑。这里有两个解决方案。
像这样定义映射,因此将为 Application.cfc 计算路径:
或者像这样更改组件路径:
问题在于
ExpandPath
和getCurrentTemplatePath()
返回的路径之间存在差异。Your syntax is OK, I've just did the same for application deep in directories tree and it works fine.
What is exact error? "invalid component definition, can't find myapp.xyz"?
Are your cfm and cfc in the same directory? (this is basically what you are trying to do)
You wont see this info by dumping the application scope. Only option is to use Application.cfc as usual cfc.
EDIT. You have two solutions here.
Define mapping like this, so path will be calculated for Application.cfc:
Or change component path like this:
Problem is in differences between paths returned by
ExpandPath
andgetCurrentTemplatePath()
.更新: 正如 Sergii 指出的,语法是有效的,但最终效果是相同的。
尝试使用这个语法
Update: As Sergii pointed out, the syntax is valid, but the net effect is the same.
Try using this syntax