🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1.在模型中定义搜索器 ``` //搜索器:格式search+字段名+Attr public function searchExamnameAttr($query, $value, $data){ $query->where('examname','like', '%'. $value . '%'); } ``` ``` 2.在控制器中使用 //没有有搜索条件时 if($val == ''){ $userinfo = ExamModel::limit($start,$limit)->order('create_time','desc')->select(); $count = count(ExamModel::select()); }else{ //有搜索条件时:withSearch $userinfo = ExamModel::withSearch(['examname'],['examname'=>$val])->limit($start,$limit)->order('create_time','desc')->select(); $count = count(ExamModel::withSearch(['examname'],['examname'=>$val])->select()); } ```