自定义列

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

            'id',
            'smid',
           [
                'attribute' => 'cname',
                'value' => function($model) {
                     return $model->trianclass ? $model->trianclass->cname : null;
                },
                'label'=>'课程名称',
               // 'filter'=>Html::activeTextInput($searchModel, 'cname',['class'=>'form-control'])
            ],
            // ['label'=>'客户',  'attribute' => 'train_class.cname',  'value' => 'train_class.cname' ],
            'year',
            'date',
            // 'end',
            // 'handling',

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

你可能感兴趣的:(自定义列)