如何像cardview一样显示Yii2索引中的数据 [英] How to displaying the datas in Yii2 index like cardview

查看:19
本文介绍了如何像cardview一样显示Yii2索引中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Yii2 高级项目中显示数据(例如:projects 表),我只需要知道如何在我的索引中显示这些内容?

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.

但有一个区别,我知道我们可以使用 DetailView::widgetGridview widget 或类似的东西,但是,我应该把这些代码放在哪里?

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.

但是,我们如何在索引中使用这些小部件并像cardview那样显示这些数据?

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

任何帮助我将不胜感激.

Any help i'll appreciated.

推荐答案

gridview 最简单的方法是基于 raw 结果管理值的回调函数

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

给定一个 gridview,你可以用适当的 html 配置每个单元格

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

通过这种方式,您可以根据与您的模型相关的值,轻松地使用您喜欢的内容构建 grdiview/表格.

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

这篇关于如何像cardview一样显示Yii2索引中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆