当前位置: 首页 > 工具软件 > RageFrame > 使用案例 >

rageframe2 SearchModel 关联查询

邵诚
2023-12-01

控制器代码

		$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;
	        },
    	],
    	......
 类似资料: