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 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择