How to displaying the datas in Yii2 index like cardview

爷,独闯天下 提交于 2019-12-25 03:54:56

问题


I'm trying to displaying the datas (for example: projects table) in my Yii2 advanced project and i just need to know how can display these things in my index?

i mean, i couldn't find any tutorial or discussion about this in the internet.

but with one diffrence, i know we can use DetailView::widget or Gridview widget or something like that, but, where should i put those codes into it?

i mean, how can use these widgets for each item like a cardview. exactly like below:

https://play.google.com/store

as you can see, each item has a cardview and another things.

But, how we can use these widgets in index and showing those datas like cardview?

Any help i'll appreciated.


回答1:


the easiest way with gridview is based on a raw result management of callback function for the value

Given a gridview you can cofigure with proper html each cell

    <?= 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;'],
        ],
       .......
       ......

In this way you can easy build the grdiview/table with the content you prefer based on value related to you model or not.



来源:https://stackoverflow.com/questions/33846976/how-to-displaying-the-datas-in-yii2-index-like-cardview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!