donvikky
(Lordvikky)
December 26, 2014, 12:47am
1
I am working on a project and I have decided to use yii 2 for it.
I need to use the ListView widget to display some items, however, I have noticed that there is no documentation for the ListView widget on the yii 2 api doc site: http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html
I have scoured google, stackoverflow etc and have not been able to find a complete example of using ListView widgets in Yii 2
I need a complete working example of using the ListView widget so that I can adapt same for my project
evstevemd
(Stefano Mtangoo)
December 26, 2014, 8:09am
2
Will coin one once am at my Laptop
But if you look at Gridview you will have idea on LV
donvikky
(Lordvikky)
December 26, 2014, 4:52pm
3
Thanks a lot Stefano. I am eagerly expecting your response. I have searched all over the net to no avail. Any code sample you provide will be highly appreciated
evstevemd
(Stefano Mtangoo)
December 27, 2014, 8:21pm
4
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return Html::a(Html::encode($model->name), ['view', 'id' => $model->id]);
},
]) ?>
As you see you can provide itemView as callable or as file as in
'itemView' =>'_myView'
donvikky
(Lordvikky)
December 30, 2014, 10:09am
5
Thanks a lot. I will try this out! Much appreciated