什么选项可以传递给play框架中的flashing

时间:2014-10-01 11:39:07

标签: scala playframework playframework-2.0

你好Grammarians,

文档仅显示:

  

flashing("success")

如果我使用play,情况是否永远不会发生?我试过“failure”& “error”他们什么都不做

1 个答案:

答案 0 :(得分:1)

您可以传入Flash个实例或String个元组。它不一定是特定的String。重要的是,您可以处理任何粘在闪存范围内的内容。

考虑这个例子(Play 2.3.4):

Application.scala

package controllers

import play.api.mvc._

object Application extends Controller {

  def index = Action { implicit req =>
    Redirect(routes.Application.flash()).flashing("something" -> "show this text")
  }

  def flash = Action { implicit req =>
    Ok(views.html.index("Flash!"))
  }

}

index.scala.html

@(title: String)(implicit flash: Flash)

<!DOCTYPE html>

<html>
  <head>
    <title>@title</title>
  </head>
  <body>
    <h1>@flash.get("something")</h1>
  </body>
</html>

路由

# Home page
GET        /                    controllers.Application.index
GET        /flash               controllers.Application.flash