控制器代码
$searchModel = new SearchModel([
'model' => CreditsLog::class,
'scenario' => 'default',
'partialMatchAttributes' => ['realname', 'member.mobile', 'member_id'], // 模糊查询
'defaultOrder' => [
'id' => SORT_DESC
],
'relations' => ['member' => ['mobile']],
'pageSize' => $this->pageSize
]);
view 页面代码
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//重新定义分页样式
'tableOptions' => ['class' => 'table table-hover'],
'columns' => [
[
'label' => '手机号',
'filter' => Html::activeTextInput($searchModel, 'member.mobile', [
'class' => 'form-control',
'placeholder' => '手机号'
]
),
'value' => function ($model) {
return $model->member->mobile;
},
],
......