[英]Is there any way to look up the controller and method names from a request in Play Framework 2.0
當我處於“動作”塊中時,如何確定哪個控制器正在呼叫我?
在Play 1.0中,您可以直接從請求對象獲取此信息。 在Play 2.0中有什么方法可以在不重新解析conf / routes的情況下進行此操作?
def myAction = {
implicit request =>
Logger.info("The controller name is " + <cname>)
Logger.info("The method name is " + <mname>)
}
我不知道一種普遍獲取該信息的方法,但是如果您只需要檢查一些特定的路線,那么這就是我的方法:
(這是Java語言,但也許您或某人可以翻譯成Scala)
String requestPath = request().path();
String routeHome = routes.Application.index().toString();
if (requestPath.equals(routeHome))
{
// user is on Application.index()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.