Concatenate strings in UrlMappings?
I'm trying to create separate controllers for admin in my application. So far I've got something like this :
"/admin/article/$action?/$id?"(controller:"adminArticle")
"/admin/comment/$action?/$id?"(controller:"adminComment")
And so on for all the admin controllers. I would like to make it simpler, tried :
"/admin/$controller?/$action?/$id?"(controller:"admin" + controller[0].toUpperCase() + controller[1..-1])
and
"/admin/$controller/$action?/$id?"(controller:"admin$controller")
but neither of thi开发者_开发问答s solutions worked. Have you any idea how can I make this mappings more dynamic?
You can customize the controller value if you use a closure.
/$mode/$contr"{
action = "someAction"
controller = {
if (params.mode == "api") {
return params.contr+"API"
}
else {
return params.contr
}
}
constraints {
mode inList:["menu", "api"]
}
}
I hope this helps!
Maybe you should not use the word "controller". I didn't try it, but this could work:
"/admin/$contr/$action?/$id?"(controller:"admin$contr") // if first letter of contr is upper case
精彩评论