//搜索+分頁顯示 public function WordSearch(){ $word = $_GET['word']?$_GET['word']:null; $list = Db::name('user')->where('area','like',"%$word")->paginate(6,false,['query'=>request()->param()]); $page = $list->render();// 把分頁數據賦值給模板變量list $this->assign('data', $list); $this->assign('page',$page); // 渲染模板輸出 return $this->fetch('FormLists'); }
要注意的是tp5在樣式上面是融合了bootstrap樣式來封裝的,所以輸出了分頁類以后只需要引入bootstrap樣式就可以了,比如:
代碼:
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">