有没有任何方法可以在Play Framework 2.0中从请求中查找控制器和方法名称



当我在Action块中时,如何确定哪个控制器在调用我?

在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()
}

最新更新