问题描述
我不了解模板处理方法的外观以及编译器对我的要求.
https://github.com/flatlizard/blog
I don't understand how template handling methods have to look like and what complier require of me.
https://github.com/flatlizard/blog
控制器:
def addPost = Action{ implicit request =>
Ok(views.html.newPost(postForm))
}
def createPost = Action { implicit request =>
postForm.bindFromRequest.fold(
hasErrors => BadRequest,
success => {
Post.create(Post(new Date, success.title, success.content))
Ok(views.html.archive("my blog", Post.all))
})
}
路线:
GET /archive/new controllers.Application.addPost
POST /archive controllers.Application.createPost
视图:
@(postForm: Form[Post])(content: Html)(implicit messages: Messages)
@import helper._
@form(routes.Application.createPost) {
@inputDate(postForm("date"))
@textarea(postForm("title"))
@textarea(postForm("content"))
<button id="submit" type="submit" value="Submit" class="btn btn-primary">Submit</button>
}
更新
我解决了在控制器文件中添加以下导入的问题:
I solved problem adding the following imports in controller file:
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
请参阅Play 2.4迁移: https://www.playframework.com/documentation/2.4.x/Migration24#I18n
See Play 2.4 migration:https://www.playframework.com/documentation/2.4.x/Migration24#I18n
推荐答案
我解决了在控制器文件中添加以下导入的问题:
I solved problem adding the following imports in controller file:
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
请参阅Play 2.4迁移: https://www.playframework.com/documentation /2.4.x/Migration24#I18n
See Play 2.4 migration: https://www.playframework.com/documentation/2.4.x/Migration24#I18n
更新
实际上这是一种不好的方法,因为此处使用的Play.current很快就会被弃用.这里是使用依赖注入的另一种解决方案:
Actually this is a bad way cause here used Play.current which will become deprecated soon. Here another solution using dependency injection:
路线:
GET /archive/new @controllers.Application.addPost
POST /archive @controllers.Application.createPost
控制器:
class Application @Inject() (val messagesApi: MessagesApi)
extends Controller with I18nSupport{
...
}
https://www.playframework.com/documentation/2.4.x/ScalaDependencyInjection
这篇关于方法的缺少参数适用... Play Framework 2.4编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!