thinkphp5 实现搜索分页能下一页保留搜索条件

时间:2022-10-27 11:55:33

正常情况下:

搜索后分页了,点击第二页,进入页面之前的搜索条件没有了.

如代码

 

$keywords=$this->request->param('keywords');

$this->view->assign('keywords',$keywords);

//查询文章 标题  关键字  描述

$blockcategory_data=ArticleModel::where(function($query) use($keywords){

$query->where('article_title','like','%'.$keywords.'%')

->whereor('article_keywords','like','%'.$keywords.'%')

->whereor('article_desc','like','%'.$keywords.'%');

})->order('article_sort desc,id desc')->paginate(5);

 

更改:

Db::name("table")->where("XXXX")->paginate(10,false,['query'=>request()->param()]); 

这才是正解!不要都把问题弄得太复杂了!

 

修改后的代码:

 

        //获取搜索

$keywords=$this->request->param('keywords');

$this->view->assign('keywords',$keywords);

//查询文章 标题  关键字  描述

$blockcategory_data=ArticleModel::where(function($query) use($keywords){

$query->where('article_title','like','%'.$keywords.'%')

->whereor('article_keywords','like','%'.$keywords.'%')

->whereor('article_desc','like','%'.$keywords.'%');

})->order('article_sort desc,id desc')->paginate(5,false,['query'=>request()->param()]);


就是在paginate里面,加上参数

paginate(5,false,['query'=>request()->param()]);

///ends