Play Framework Notes - fcrimins/fcrimins.github.io GitHub Wiki

Main Concepts for Scala

Play, Anatomy of a web framework: The Web Server

SecureSocial is an authentication module for Play Framework applications

Generating Play Framework 2 CRUD forms with Cato (1/5/17)

Forms

  • "In the success case, we’re sending a Redirect with a route to routes.Application.home here instead of rendering a view template. This pattern is called Redirect after POST, and is an excellent way to prevent duplicate form submissions."

Templates

  • "A template is like a function, so it needs parameters, which must be declared at the top of the template file."
  • Template Common Use Cases
  • views.html.[OptionalDir.]index is a Scala class generated by Twirl from the views/[OptionalDir/]index.scala.html template (note how views.html.index(testRelativity) is called in Application.scala

Session and Flash scopes

  • "keep data across multiple HTTP requests"

Cookies

Routing

Database

Actions, Controllers and Results

  • "A Controller is nothing more than an object that generates Action values. Controllers can be defined as classes to take advantage of Dependency Injection or as objects."
  • "Note: Keep in mind that defining controllers as objects will not be supported in future versions of Play. Using classes is the recommended approach."
  • Use the Action companion object to construct Action instances, all of which return Results.
  • TODO
    • def fredtest(name: String) = TODO
  • Ok(out) is equivalent to:
Result(
  header = ResponseHeader(200, Map.empty),
  body = HttpEntity.Strict(ByteString(out), Some("text/plain"))
)