yii GridView 多对多

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

内容简介:一个游戏有多个开发商和发行商,一个开发商也有多个游戏。他们是多对多的关系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


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

查看所有标签

猜你喜欢:

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

Beginning iPhone and iPad Web Apps

Beginning iPhone and iPad Web Apps

Chris Apers、Daniel Paterson / Apress / 2010-12-15 / USD 39.99

It seems that everyone and her sister has developed an iPhone App—everyone except you, the hard-working web professional. And now with the introduction of the iPad, you may even feel farther behind. B......一起来看看 《Beginning iPhone and iPad Web Apps》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具