标签:n6k fnr nod arc 12c bof swt bfd ble
1.model中建立关联
public function getUser(){ return$this->hasOne(User::className(),[‘id‘=>‘uid‘]) ; }
2.在视图中
<?= GridView::widget([ ‘dataProvider‘ => $dataProvider, ‘columns‘ => [ // [‘class‘ => ‘yii\grid\SerialColumn‘], 取消掉编号 [‘attribute‘=>‘id‘, ‘contentOptions‘=>[‘width‘=>‘30‘], ], ‘code‘, ‘name‘, ‘population‘, [ ‘attribute‘=>‘username‘, ‘label‘=>‘作者‘, ‘value‘=>‘user.username‘, ], ‘create_at‘, // ‘update_at‘, [‘class‘ => ‘yii\grid\ActionColumn‘], ], ]); ?>
3.在model中增加属性
public function attributes() { return array_merge(parent::attributes(),[‘username‘]);// TODO: Change the autogenerated stub }
4.效果
标签:n6k fnr nod arc 12c bof swt bfd ble
原文地址:http://www.cnblogs.com/hsd1727728211/p/6013473.html