老难了:使用GET方法搜索后的分页问题?
本帖最后由 seahorse 于 2013-7-11 09:07 编辑/*CI2.1.3*/用GET方法提交搜索表单,控制器search.php中对搜索的结果进行分页设置,代码如下:function index(){ $query = array(); $category_filter = $this->input->get('category', TRUE); if(!empty($category_filter)) { $query[] = 'category='.$category_filter; } $direction_filter = $this->input->get(' direction', TRUE); if(!empty($direction_filter)) { $query[] = 'direction='.$ direction_filter; } // 获取记录总数 $total_row = $this->My_model->get_research_result_count($category_filter, $direction_filter); $conifg[‘total_row’]= $total_row; $conifg[‘base_url’]= base_url.’index.php/search/index?’.implode(‘$’, $query); $conifg[‘per_page’]= ‘8’; $conifg[‘uri_segment’]= ‘3’; $this->pagination->initialize($config); $data[‘searchresult’] = $this->My_model->get_research_result($conifg[‘per_page’], $this->uri->segment(3), $category_filter, $direction_filter); $this->load->view(‘main’, $data);}模型和视图代码略。问题:搜索结果第一页能够正常显示,但点击下一页,就显示出数据库的全部记录了。搜索后地址栏的uri为:http://localhost/index.php/search/index?category=1&direction=2点击第2页就显示出数据库所有记录了,地址栏uri为:http://localhost/index.php/search/index?category=1/8页数8跑到uri的最后了,而且搜索条件也少了一个。请高手指点?
http://codeigniter.org.cn/forums/thread-17104-1-1.html To: wingofsky
使用这个方法测试失败。好像有人把搜索选项存储在session中,但不知道具体如何实现? 请高手指点 seahorse 发表于 2013-7-12 08:49 static/image/common/back.gif
To: wingofsky
使用这个方法测试失败。好像有人把搜索选项存储在session中,但不知道具体如何实现? 请 ...
传到SESSION就是直接将所有数据打包传到SESSION里呀
http://codeigniter.org.cn/user_guide/libraries/sessions.html
大哥, 我想知道session解决搜索分页的具体方法,而不是这个帮助手册 本帖最后由 Ahgigu 于 2013-7-17 18:16 编辑
不需要session,
加上suffix配置项就行了
$config['suffix'] = strlen($_SERVER['QUERY_STRING']) > 0 ? "?{$_SERVER['QUERY_STRING']}" : '';
$config["first_url"] = $config["base_url"]. $config["suffix"];//为“第一页”也生成带query string的链接
另外在github上最新的实现
https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Pagination.php
增加了一个reuse_query_string配置项,就不需要以上配置了。
希望对你有帮助。 问题解决,非常感谢! seahorse 发表于 2013-7-19 08:23 static/image/common/back.gif
问题解决,非常感谢!
请问你有开始用3么?
没有修改CI分页类源码,制作简单的配置即可!
原帖地址:http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=18776
// 这段代码和以前的配置没差别
$config['base_url'] =site_url('shop/membe');
// 追加在所有自动生成的分页链接里的后面,第一页除外
$config['suffix'] = '?mid='.$member_id;
// 第一页默认是$config['base_url'],所有需要手动设置成如下的链接
$config['first_url'] = site_url('shop/membe?mid='.$member_id); Ahgigu 发表于 2013-7-17 18:15
不需要session,
加上suffix配置项就行了
问题解决,谢谢
页:
[1]