【问题标题】:how to get the controller inside of playframework template?如何在 playframework 模板中获取控制器?
【发布时间】:2014-05-26 16:49:06
【问题描述】:

我用的是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())

那我就可以直接到对应的controller pagelist了。

【问题讨论】:

    标签: scala playframework-2.0 template-engine playframework-2.2


    【解决方案1】:

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

    无论如何,无论你“传入”什么,“传入”都是控制器的工作——记住所有这些都是参数。如果你真的想要控制器,那么在你创建页面的控制器中使用 this 关键字:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 2014-05-23
      • 2020-02-27
      • 1970-01-01
      • 2011-03-16
      相关资源
      最近更新 更多