I would like to render the name of the current action and controller in the view of a Play 2 Application. How do I do this?
In Scala, we use the following function for this purpose:
def actionFromRequest(request: RequestHeader): String = {
request.tags.get(Routes.ROUTE_CONTROLLER).flatMap {
c => request.tags.get(Routes.ROUTE_ACTION_METHOD).map {
a => c + "." + a
}
}.getOrElse("ActionControllerCannotBeRetrieved")
}
Output here is "ControllerName.ActionName". While you have implicit request in your action, you just simply can include this function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.