Scala 如何在playframework模板中获取控制器?
我使用了playframework2.2: 我的模板是:Scala 如何在playframework模板中获取控制器?,scala,playframework-2.0,template-engine,playframework-2.2,Scala,Playframework 2.0,Template Engine,Playframework 2.2,我使用了playframework2.2: 我的模板是: @(topiclink:String, head: String, rate: Int, topicid:Int, summary: String, pic_url:String) @if(topiclink=="Shoplist"){ <a class="list-group-item" href="@routes.ShoplistController.pagelist(topicid.toString())"> }else
@(topiclink:String, head: String, rate: Int, topicid:Int, summary: String, pic_url:String)
@if(topiclink=="Shoplist"){
<a class="list-group-item" href="@routes.ShoplistController.pagelist(topicid.toString())">
}else {
<a class="list-group-item" href="@routes.PageController.pagelist(topicid.toString())">
}</a>
然后可以直接@topiclink.pagelist(topicid.tostring())
我可以直接找到相应的控制器页面。
直接在控制器中传递可能是个坏主意——考虑控制器创建表示数据(PaulListar)的对象。 不管怎样,无论你“传入”,控制器的工作就是“传入”——记住所有这些都是参数。如果确实需要控制器,则在创建页面的控制器中使用this关键字:
views.html.index.myPage(this, otherParam, ...)
views.html.index.myPage(this, otherParam, ...)