2016-07-22 57 views
0

如何將類添加到Html :: ul()方法。我有以下代碼:將類添加到Html :: ul()方法

<?= Html::ul($posts, ['item' => function($item, $index) { 
    return Html::tag(
     'li', 
     $this->render('post', ['item' => $item]), 
     ['class' => 'post'] 
    ); 
}]) ?> 

我嘗試下面的代碼:

<?= Html::ul($posts, ['item' => function($item, $index) { 
    return Html::tag(
     'li', 
     $this->render('post', ['item' => $item]), 
     ['class' => 'post'] 
    ); 
}], [ 'class' => 'myclass' ]) ?> 

但它呈現UL如下:在yii2 document

<ul 0-class="myclass"> 

沒有提及。

任何幫助將是可觀的。謝謝。

回答

1

下面的代碼工作!可能對某人有幫助。

echo Html::ul($posts, ['item' => function($item, $index) { 
      return Html::tag(
       'li', 
       $this->render('post', ['item' => $item]), 
       ['class' => 'post'] 
      ); 
     }, 'class' => 'myclass']);