多条件搜索,多条件筛选是常见的功能,以下是ThinkPHP6的写法,当然ThinkPHP5也是一样的写法。
<?php public function vod(Request $request) { $where=[]; //定义$where为数组 if(!empty($request->param('searchParams'))){ $searchParams=json_decode($request->param('searchParams'),true); if(!empty($searchParams['name'])){ $where[] = array('name', 'like', $searchParams['vod_name'].'%'); } if(!empty($searchParams['vod_year'])){ $where[] = array('vod_year', '=', $searchParams['vod_year']); // $where .= ['vod_year'=>['=',$searchParams['vod_year']]]; } if(!empty($searchParams['vod_cid'])){ $where[] = array('vod_cid', '=', $searchParams['vod_cid']); // $where .= ['vod_cid'=>['=',$searchParams['vod_cid']]]; } } } ?>
文章评论(0)