我正在尝试在Yii2高级项目中显示数据(例如:projects
表),我只需要知道如何在索引中显示这些东西
我的意思是,我在网上找不到任何关于这方面的教程或讨论。
但有一点不同,我知道我们可以使用DetailView::widget
或Gridview widget
或类似的东西,但是,我应该把这些代码放在哪里?
我的意思是,如何像卡片视图一样为每个项目使用这些小部件。如下所示:
https://play.google.com/store
正如您所看到的,每个项目都有一个卡片视图和其他内容。
但是,我们如何在索引中使用这些小部件,并显示像cardview
这样的数据?
任何帮助我都将不胜感激。
使用gridview最简单的方法是基于值的回调函数的raw
结果管理
给定一个网格视图,你可以用适当的html共同绘制每个单元格的
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii'grid'SerialColumn'],
[
'attribute' => 'yuor_attibute', // you can use a dummy attribute in this case
'label' => 'your label',
'format' => 'raw',
'value' => function ($model) {
return "<a href='./yourPath/view?id=". $model->your_column ."' class = 'btn btn-success glyphicon glyphicon-user ' > </a>";
},
'contentOptions' => ['style' => 'width:80px; text-align: center;'],
'headerOptions' => ['style' => 'text-align: center;'],
],
[
'attribute' => 'yuor_attibute', // you can use a dummy attribute in this case
'label' => 'your 2 label',
'format' => 'raw',
'value' => function ($model) {
return "<img src='./yourPath/image.jpg">";
},
'contentOptions' => ['style' => 'width:400; height 400 px;'],
'headerOptions' => ['style' => 'text-align: center;'],
],
[
'attribute' => 'yuor_attibute', // you can use a dummy attribute in this case
'label' => 'your 3 label',
'format' => 'raw',
'value' => function ($model) {
return "< ****the html you prefer ***>";
},
'contentOptions' => ['style' => 'width:400; height 400 px;'],
'headerOptions' => ['style' => 'text-align: center;'],
],
.......
......
通过这种方式,您可以根据与您的模型相关或不相关的值,使用您喜欢的内容轻松构建grdiview/表。