Codeigniter引导搜索结果分页丢失

时间:2015-05-16 20:37:08

标签: php twitter-bootstrap codeigniter pagination

我正在使用CodeIgniter分页类,一切正常。搜索时找到了数据,但分页链接不符合搜索结果。 例如:搜索结果是数据之一,但链接页面有两个。

这是我的代码:

function view_search($offset=0) {
$jml = $this->db->get('kategori');
  $config['base_url'] = base_url().'paging/cari_data';
  $config['total_rows'] = $jml->num_rows();
  $config['per_page'] = 5; 
  $config['uri_segment'] = 3; 
  $config['use_page_numbers'] = TRUE;
  $config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative; top:-25px;'>";
  $config['full_tag_close'] ="</ul>";
  $config['num_tag_open'] = '<li>';
  $config['num_tag_close'] = '</li>';
  $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
  $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
  $config['next_tag_open'] = "<li>";
  $config['next_tagl_close'] = "</li>";
  $config['prev_tag_open'] = "<li>";
  $config['prev_tagl_close'] = "</li>";
  $config['first_tag_open'] = "<li>";
  $config['first_tagl_close'] = "</li>";
  $config['last_tag_open'] = "<li>";
  $config['last_tagl_close'] = "</li>";

  $this->pagination->initialize($config);
  $data['halaman'] = $this->pagination->create_links();
  $data['offset'] = $offset;
  $data['data'] = $this->model_pagination->cari_data($config['per_page'], $offset);
  $this->load->view('view_paging',$data);
 }  

型号:

function cari_data($num,$offset)  {
    $cari = $this->input->POST ('cari');
    $this->db->order_by('id_kategori','DESC');
    $this->db->like('nama_kategori', $cari);
    $query = $this->db->get("kategori",$num, $offset);
    return $query->result();
 }

查看:

<form role="form" method="post" action="<?php echo site_url('paging/view_search');?>">
<input type=text name=cari> <input type=submit value="cari">
</form>

1 个答案:

答案 0 :(得分:0)

您使用了

    $config[‘use_page_numbers’] = TRUE;

因此分页使用页码。没有抵消。 评论此行(默认为false)。

    //$config[‘use_page_numbers’] = TRUE; 

然后你的view_search($ offset = 0)函数将获得正确的$ offset值。