开发者

In grails how to insert additional parameters (from session) in all url's

I would like to add a开发者_Python百科n additional parameter in my url, the use case is the following:

When user do their login they also specify a 'company' name and from that moment on, all urls should map to:

 /$company/$controller/$action/$id

The main idea is to have the current company name available in all url's, have it bookmarkable, and not to have to pass the company name everywhere as a request parameter.

Also, once users are logged in it is acceptable to have the chosen company name in session scope.

What is the right way of inserting this parameter in all our urls? I tried to modify my UrlMappings mapping, but I didn't found a way to insert the company name.

Thanks,


I think that what you need is a named URL mapping along the lines of

name companyMapping: "/$company/$controller/$action/$id" {
        }

and in your GSPs refer to your named mapping in all your link tags:

 <g:link mapping="companyMapping" controller="abcd" action="xyz" params="[company:userCompany]"> my link text </g:link>

You'll have to store the userCompany in the session when a user initially logs in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜