railo application.cfc this.mappings not working

自古美人都是妖i 提交于 2019-12-04 01:42:57

问题


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.


回答1:


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().




回答2:


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>


来源:https://stackoverflow.com/questions/6875621/railo-application-cfc-this-mappings-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!