thinkphp 搜索分页功能处理我用的存session的方法,亲测能用,供大家参考。
1.Controller控制器
public function information_cate_lists(){/* 资讯分类 -> 搜索 */$cate_title=isset($_POST['cate_title'])?$_POST['cate_title']:$_SESSION['cate_title2'];//判断cate_title存在与否,判断取值,解决下一页问题$datemin=isset($_POST['datemin'])?$_POST['datemin']:$_SESSION['datemin2'];//判断datemin存在与否,判断取值,解决下一页问题$datemax=isset($_POST['datemax'])?$_POST['datemax']:$_SESSION['datemax2'];//判断datemax存在与否,判断取值,解决下一页问题$_SESSION['cate_title2']=$cate_title;//本地存储name值$_SESSION['datemin2']=$datemin;//本地存储datemin值$_SESSION['datemax2']=$datemax;//本地存储datemax值$cate_title3=$_SESSION['cate_title2'];//赋值$datemin3=$_SESSION['datemin2'];//赋值$datemax3=$_SESSION['datemax2'];//赋值$where = array(array('EGT',strtotime($datemin3." 00:00:00")),array('ELT',strtotime($datemax3." 23:59:59")));$map =array("cate_title like '%$cate_title3%'");if(empty(IS_POST)){$soso = '';}else if($datemin <> null and $datemax <> null and $cate_title <> null){$soso = array(array('cate_time'=>$where),$map);}else if(empty($cate_title)){$soso = array('cate_time'=>$where);}else{$soso = $map;}/* 资讯列表分页详情 */$count= M('admin_information_cate') -> where($soso) ->count(); //查询满足条件的总记录数$p = getPage($count,10); $show = $p->show(); // 分页显示输出$row= M('admin_information_cate')-> where($soso)->order('id')->limit($p->firstRow.','.$p->listRows)->select();$this->assign('row',$row);$this->assign('count',$count);$this->assign('show',$show);$this->display();}
2.View视图
<form action="{:U('information_cate_lists')}" method="post"><div class="text-c"> 日期范围:<input type="text" οnfοcus="WdatePicker({skin:'whyGreen',maxDate:'%y-%M-%d'})" id="datemin" name='datemin' class="input-text Wdate" style="width:120px;">-<input type="text" οnfοcus="WdatePicker({skin:'whyGreen',maxDate:'%y-%M-%d'})" id="datemax" name='datemax' class="input-text Wdate" style="width:120px;"><input type="text" class="input-text" style="width:250px" placeholder="输入分类名称" id="cate_title" name="cate_title"><button type="submit" class="btn btn-success" id="butt"><i class="Hui-iconfont"></i> 搜分类</button></div></form>
注意:日期我是用的WdatePicker日期插件,需要下载请到/下载参考;分页请参考thinkphp3.2.3分页完整实例。