如何在Codeigniter中访问没有查询字符串的分页网址?

时间:2018-09-08 03:48:32

标签: codeigniter codeigniter-3

我想在CodeIgniter中访问分页URL而没有查询字符串,例如

  

http://127.0.0.1/hmvc/business_list/20

现在我得到的网址是

  

http://127.0.0.1/hmvc/business_list/?p=2

通过这种方式,我无法读取URL段并且分页无法正常工作。它应该在第一页上返回0-10条记录,在第二页上返回10-20条记录,依此类推。但是在我的情况下,根据URL段,它在第一页上返回0-10,然后在第二页上返回2-12。

这是我的代码:

public function index()
{
    $query = $this->db->get('categories','10',$this->uri->segment(2));
    $data['results'] = $query->result();
    $data['seg'] = $this->uri->segment(2);
    $query2 = $this->db->get('categories');

    $config['base_url'] = base_url().'business_list/';


     $config['total_rows'] = $query2->num_rows();
    $config['per_page'] = 10;
  //  $config['uri_segment'] = $this->uri->segment(2);
   // $config['page_query_string'] = false;
    $config['page_query_string'] = true;
    $config['full_tag_open'] = "<ul class='pagination pagination-right margin-none'>";
    $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['links'] = $this->pagination->create_links();
    $data['title'] = "Business List";

    $this->load->view('categories',$data);
   }

如何纠正此问题?

1 个答案:

答案 0 :(得分:0)

使用以下配置进行分页

$config['per_page'] = 10;
$config['uri_segment'] = 2;

$config['full_tag_open'] = '<ul class="pagination pagination-right margin-none">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_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['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['enable_query_strings'] = TRUE;