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

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

http://www.waitingfy.com/archives/5312

5312

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.