php - 在 Yii2 的索引(或另一个 View )上使用另一个 View GridView

标签 php mysql css gridview yii2

我正在尝试从另一个 View 使用这些数据的表中获取数据,我想知道我是否可以在我的 Yii2 Index 页面 View 中显示它们,就像每个带有 cardview 的元素一样和细节。

就像我之前的回答一样: https://stackoverflow.com/a/33847647/4960200

这可能吗?

我可以在哪里或如何在我的 Yii2 索引 中使用该表中的数据?

或者老实说,我不能在我的 views/site/index.php 中这样做:

<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>

关于在索引中使用它并在索引中显示表中的数据,我应该了解什么?

最佳答案

在这个示例中,我假设卡片都包含在 dataProvider $dataProvider->models 中,并且每个模型都包含一个图像和一个标题

这可能是 View /元素的 index.php

    <?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>

关于php - 在 Yii2 的索引(或另一个 View )上使用另一个 View GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34162063/

相关文章:

php - 读取带有空格和 () 的文件名

php - 有什么方法可以更快地提取字符串?

mysql group_concat 将一张表连接到另一张表

php - 在 php 中使用 mysql 查询中的类/对象属性

php - 从 imap_search() 读取电子邮件时出现额外字符

html - 表格单元格在连字符处换行

Php 5.6 (fpm) - 带有 mysql 命令的旧文件可以工作 - 当它被弃用时如何?

javascript - 来自 mysql 的 json 编码返回 null

css - 将 url 重写到远程服务器时包括 css 和图像

JavaScript 无法提取引号 css 属性