2014-11-11 09:03:08 4121次浏览 1条回答 2 悬赏 0 金钱

用GridView来生成表格时有一个column如:country_id是国家编号,在表格中我想显示对应的国家名称。国家全在变量$countries中。那country_id该怎么弄呢?
GridView::widget([

     'dataProvider' => $dataProvider,
     'columns' => [
           ...
          [ 'attribute' => 'country_id'],
           ...
     ],
 ]); 
补充于 2014-11-11 09:45

已经解决了这个要做关联查询的
[

	        'attribute' => 'country_id',
     		'content'=>function ($model, $key, $index, $column){
			        return $model->country->name;
			    },
		],

最佳答案

  • nswindlights 发布于 2014-11-11 09:45 举报

    已经解决了这个要做关联查询的
    [

    	        'attribute' => 'country_id',
         		'content'=>function ($model, $key, $index, $column){
    			        return $model->country->name;
    			    },
    		],
    
  • 回答于 2014-11-11 09:21 举报
    'columns' => [
               ...
              [ 'attribute' => 'country_id',
    'value'=>function($data) {
    return $data->cuntry_id . $data->xxxx
    }
    
          ],
           
     ],
    
您需要登录后才可以回答。登录 | 立即注册
nswindlights
总监

nswindlights 江苏太仓

注册时间:2014-09-18
最后登录:2020-03-30
在线时长:74小时58分
  • 粉丝5
  • 金钱986
  • 威望80
  • 积分2526

热门问题