Railo application.cfc this.mappings 不起作用

发布于 2024-11-26 21:43:54 字数 875 浏览 1 评论 0原文

我正在使用最新版本的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两个我 2024-12-03 21:43:54

你的语法没问题,我刚刚对目录树深处的应用程序做了同样的事情,它工作得很好。

但是,我的组件无法通过此映射访问,

确切的错误是什么? “组件定义无效,找不到 myapp.xyz”?

你的cfm和cfc在同一个目录下吗? (这基本上就是你想要做的)

当我在代码中对应用程序变量执行 cfdump 时,它将显示“applicationname”设置为“MyApp”,但没有显示任何映射。

通过转储应用程序范围,您将看不到此信息。唯一的选择是像往常一样使用 Application.cfc。

<cfset app = CreateObject("component",  "application") />
<cfdump var="#app#">

编辑。这里有两个解决方案。

像这样定义映射,因此将为 Application.cfc 计算路径:

<cfset this.mappings["/myapp2"] = getDirectoryFromPath(getCurrentTemplatePath())>

或者像这样更改组件路径:

<cfset MyObject = CreateObject("component",  "myapp.data.MyObject") />

问题在于 ExpandPathgetCurrentTemplatePath() 返回的路径之间存在差异。

Your syntax is OK, I've just did the same for application deep in directories tree and it works fine.

however, my components cannot be accessed by this mapping,

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)

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.

You wont see this info by dumping the application scope. Only option is to use Application.cfc as usual cfc.

<cfset app = CreateObject("component",  "application") />
<cfdump var="#app#">

EDIT. You have two solutions here.

Define mapping like this, so path will be calculated for Application.cfc:

<cfset this.mappings["/myapp2"] = getDirectoryFromPath(getCurrentTemplatePath())>

Or change component path like this:

<cfset MyObject = CreateObject("component",  "myapp.data.MyObject") />

Problem is in differences between paths returned by ExpandPath and getCurrentTemplatePath().

合久必婚 2024-12-03 21:43:54

更新: 正如 Sergii 指出的,语法是有效的,但最终效果是相同的。

尝试使用这个语法

<cfcomponent>
    <cfset THIS.Name = "MyApp">
    <cfset THIS.mappings = { "/myapp" = ExpandPath(".") } >
</cfcomponent>

Update: As Sergii pointed out, the syntax is valid, but the net effect is the same.

Try using this syntax

<cfcomponent>
    <cfset THIS.Name = "MyApp">
    <cfset THIS.mappings = { "/myapp" = ExpandPath(".") } >
</cfcomponent>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文