Play reverse routing - getting absolute url

不羁的心 提交于 2019-12-11 13:56:23

问题


How can I get the absolute URL in play 2.2 scala when doing the following:

val promoLink = routes.Promotions.promotionsCategory(DOCID, slug)


//routes file

GET /promotions/:DOCID:/slug     controllers.Promotions.promoCat(DOCID, slug)

As it stands I get a "found : play.api.mvc.Call" type mismatch on expecting a string

thanks


回答1:


I suppose your promoLink should be a String containing an URL? Your question sounds a bit unclear.

If so then you probably need this:

val promoLink = routes.Promotions.promotionsCategory(DOCID, slug).absoluteURL(false)(request)

false in the .absoluteURL(false) stands for the isSecure parameter which will give you http or https url.

If you have an implicit request in scope you may omit the last (request) part



来源:https://stackoverflow.com/questions/22536327/play-reverse-routing-getting-absolute-url

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