[英]How can I render the current controller and action name in the view of Play Framework 2?
我想在Play 2應用程序的視圖中呈現當前操作和控制器的名稱。 我該怎么做呢?
在Scala中,我們使用以下函數來實現此目的:
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")
}
這里的輸出是“ControllerName.ActionName”。 雖然您在操作中有隱式請求,但您只需包含此功能即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.