2016-07-26 43 views
1

Stackoverflow獲取項目數itemViewViewViewView中 - Yii2

如何獲取itemView計數。我想在ListView中的每個第三項上做一些事情。

echo ListView::widget([ 
    'dataProvider' => $modelDataProvider, 
    'itemView'  => '_item_view', 
    'viewParams' => [ 
     'count' => $itemcount // How to get this variable? 
    ], 
]) 

// _item_view.php 

if($count % 3 == 0) { 
    // this item is the third in a row, do something special 
} 

任何幫助表示讚賞!

回答

2

找到了答案。 Yii2的ListView自己注入$index參數。

您可以在itemView中使用該參數。