如何让控制器进入游戏框架模板?

时间:2014-04-12 13:36:03

标签: 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 {
 <a class="list-group-item" href="@routes.PageController.pagelist(topicid.toString())"> 

}</a>

我想写更多的OOP,我的意思是我想使用参数:

@(topiclink:Controller, head: String, rate: Int, topicid:Int, summary: String, pic_url:String)

然后可以直接@ topiclink.pagelist(topicid.tostring())

然后我可以直接进入相应的控制器页面列表。

1 个答案:

答案 0 :(得分:0)

直接传入控制器可能是一个坏主意 - 考虑让控制器创建表示所需数据(页面列表)的对象。

无论你输入什么&#34;,控制器的工作都是&#34;传递给&#34; - 记住所有这些都是参数。如果您真的想要控制器,那么在您创建页面的控制器中使用 this 关键字:

views.html.index.myPage(this, otherParam, ...)