dream07769 2015-12-08 17:18
浏览 64
已采纳

使用另一个视图在Yii2中的索引(或另一个视图)上的GridView

I'm trying to get the datas from a table which those datas are using by another view and i was wondering if i could show them in my Yii2 Index page view like each item with a cardview and details.

Exactly like my previous answer about that: https://stackoverflow.com/a/33847647/4960200

Is this possible?

Where or how can I use the datas from that table in my Yii2 index?

Or honestly, I couldn't do that in my views/site/index.php like this:

<div class="container" style="margin-top: 10px; background-color: white">
    <div class="row">
        <a class="btn btn-raised btn-sm btn-success pull-right" style="margin-right: 20px;margin-top: 20px">MORE</a>

        <h3 style="margin-left: 20px">Something</h3>

        <div class="container" style="margin-top: 20px">

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

        </div>
    </div>

What should I learn about using this in my index and showing those datas from a table in index?

  • 写回答

1条回答 默认 最新

  • dongluanguang4774 2015-12-08 20:53
    关注

    In this sample i suppose that the cards are all contained in the dataProvider $dataProvider->models and for each model contain an image and a title

    this could be the index.php for views/project

        <?php
    
        use yii\helpers\Html;
    
    
    
        // title and breadcrumbs not for the moment
    
        ?>
        <div class="project-index">
    
            <h2>CARD INDEX TITLE</h2>
            <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    
         <?php
    
    $nCardXRow = 4;
    $cnt = 0;
    echo "<div class='row'>"; // open a new row of 4 card
    foreach ($dataProvider->models as $card) {
        echo "div class='card-container col-md-3'><div><img src='" . $card->header.jpg . "'></div><div>" . $card->title . "</div></div>";
        $cnt++;
        if ($cnt == $nCardXRow) {
            echo "</div><!-- close row -->";
            echo "<div class='row'>";  // open a new row
            $cnt = 0;
        }
        echo "</div><!-- close row last row-->";
      }
    ?>
    
        </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器