yii GridView 多对多

栏目: PHP · 发布时间: 6年前

内容简介:一个游戏有多个开发商和发行商,一个开发商也有多个游戏。他们是多对多的关系5312

yii GridView 多对多

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            // 'id',
            // 'game_name',
            [
                'label' => 'logo_img',
                'value' => function($model){
                    return '<img src="' . $model->logo_img . '" style="width:200px;"></img>';
                },
                'format' => 'raw',
            ],

            [
                'label' => '游戏名称',
                'value' => function($model){
                            return Html::a($model->game_name, ['steamtopgame/view', 'id' => $model->id]);
                        },
                'format' => 'raw',
            ],

            'current_user_count',
            'high_user_count',
            // 'scrapy_date',
            [
                'label' => '开发商',
                'value' => function($model){
                            $result = '';
                            for($i = 0; $i < count($model->steamGameDevs); $i++){
                                // $result = $result . $model->steamGameDevs[$i]->dev->dev_name;
                                $result = $result . Html::a($model->steamGameDevs[$i]->dev->dev_name, ['steamdevdetail/view', 'id' => $model->steamGameDevs[$i]->dev->id]);
                                if($i != count($model->steamGameDevs) - 1){
                                    $result = $result . '<br/>';
                                }
                            }
                            return $result;
                        },
                'format' => 'raw',
            ],
            [
                'label' => '发行商',
                'value' => function($model){
                            $result = '';
                            for($i = 0; $i < count($model->steamGameSells); $i++){
                                // $result = $result . $model->steamGameSells[$i]->sell->sell_name;

                                $result = $result . Html::a($model->steamGameSells[$i]->sell->sell_name, ['steamselldetail/view', 'id' => $model->steamGameSells[$i]->sell->id]);
                                if($i != count($model->steamGameSells) - 1){
                                    $result = $result . '<br/>';
                                }
                            }
                            return $result;
                            // return join(', ', yii\helpers\ArrayHelper::map($model->steamGameSells, 'sell_id', 'sell_id'));
                        },
                'format' => 'raw',
            ],
            [
                'label' => '最高在线人数占比',
                'value' => 'totalPercent'
            ]
            

            // ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

一个游戏有多个开发商和发行商,一个开发商也有多个游戏。他们是多对多的关系

5312


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Art and Science of Java

The Art and Science of Java

Eric Roberts / Addison-Wesley / 2007-3-1 / USD 121.60

In The Art and Science of Java, Stanford professor and well-known leader in CS Education Eric Roberts emphasizes the student-friendly exposition that led to the success of The Art and Science of C. By......一起来看看 《The Art and Science of Java》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具