2
我使用的IntelliJ 14遊戲框架,我認爲框架的版本號爲2的關於信息向我表明:關於發揮框架驗證表單
[info] The current project is built against Scala 2.10.4
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugi
n, play.Play, play.PlayJava, play.PlayScala, play.twirl.sbt.SbtTwirl, com.typesafe.sbt.jse.SbtJsEngine, com.typesafe.sbt.jse.Sb
tJsTask, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.webdriver.SbtWebDriver, com.typesafe.sbt.coffeescript.SbtCoffeeScript, c
om.typesafe.sbt.less.SbtLess, com.typesafe.sbt.jshint.SbtJSHint, com.typesafe.sbt.rjs.SbtRjs, com.typesafe.sbt.digest.SbtDigest
, com.typesafe.sbt.mocha.SbtMocha, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.Sb
tNativePackager
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
我試圖創建一個登錄表單,它運行良好,但我無法正確驗證它,並顯示錯誤消息。見我的代碼波紋管:
POST /authorize controllers.LoginController.authorize
控制器階:
package controllers
import models.{DB, User}
import play.api.data.Form
import play.api.data.Forms._
import play.api.libs.json.Json
import play.api.mvc._
/**
* Created by jlopesde on 26-12-2014.
*/
object LoginController extends Controller {
val loginForm: Form[User] = Form (
mapping (
"user" -> nonEmptyText,
"password" -> nonEmptyText
)(User.apply)(User.unapply)
verifying ("Invalid login", f => true)
)
def index = Action {
Ok(views.html.login("ok"))
}
def authorize = Action {implicit request =>
// get user from request
val user = loginForm.bindFromRequest().get
// query user database
val _user = DB.query[User].whereEqual("login", user.login).whereEqual("password", user.password).fetchOne()
var response = _user match {
case None => "KO"
case _ => "OK"
}
if (response.equals("OK")) {
//send to index page
Redirect(routes.Application.index()).withSession("user" -> user.login)
} else {
Redirect(routes.LoginController.index())
}
}
}
的login.html
:
@(message: String)
@(myForm: Form[User])
@import helper._
@import models.User
@main("This is login") {
@helper.form(routes.LoginController.authorize()) {
<label for="user">username:</label> <input id="user" name="user" type="text">
<label for="password">Password:</label><input id="password" name="password" type="password">
<button>Login</button>
}
}
的問題是,我不能讓工作,娛樂不承認鍵入myForm
,我應該以某種方式發送它,但它期望一個字符串,而不是一個表單。 我嘗試了幾個例子,但都沒有工作。
Compilation error
not found: value myForm
In C:\Users\jlopesde\playprojects\my-first-app\app\views\login.scala.html:2
[email protected](message: String)
[email protected](myForm: Form[User])
[email protected] helper._
[email protected] models.User
5
[email protected]("This is login") {
7
好吧,那些消息是來自遊戲模板,我真的不明白是什麼意思。我會嘗試做修改和測試。非常感謝。 –
我的朋友感謝你,像魅力一樣工作! –