/* 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的最后了,而且搜索条件也少了一个。请高手指点?