0

我用playframework2.2:如何獲取playframework模板中的控制器?

我的模板是:

@(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:Controller, head: String, rate: Int, topicid:Int, summary: String, pic_url:String) 

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

然後,我可以直接進入對應的控制器頁面列表。

回答

0

直接傳入控制器可能是一個壞主意 - 考慮讓控制器創建表示所需數據(頁面列表)的對象。

不管你「傳入」什麼,控制器的工作是「傳入」 - 記住所有這些東西都是參數。如果你真的想要控制器,那麼在你創建頁面的控制器中使用這個關鍵字:

views.html.index.myPage(this, otherParam, ...) 
相關問題