【问题标题】:Pagination with search for all pagination links in codeigniter在codeigniter中搜索所有分页链接的分页
【发布时间】:2015-10-27 02:28:46
【问题描述】:

我们使用分页进行搜索,但它仅在第一页上有效,当我在分页中单击第二页时它不起作用。我试图通过创建搜索关键字会话来解决此问题,但无法正常工作。 请为此提供好的解决方案。

控制器代码:

    function xyz(){
    $this->load->library('pagination');
    $config['base_url'] = "http://localhost/rainbow/admin/postList/xyz";
    $config['per_page'] = 10;
    $config['total_rows'] = $this->post_model->list_count();
    $config['uri_segment'] = 3;
    $config['page_query_string'] = TRUE;
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $this->pagination->initialize($config); 

    $data['lists']=$this->post_model->listing($config["per_page"], $page);
    $this->load->view('includes/header');
    $this->load->view('listing/listing_post',$data);
    $this->load->view('includes/footer');

}

型号代码:

function search_listing($limit, $start)
{
    if(isset($this->input->get('search')))
    {
        $this->db->like('post_name',$this->input->get('search'))
    }
    $this->db->limit($limit, $start);
    $query=$this->db->get('blog');
    return $query->result();
}

我们应用了 Temporary DataTable Search Jquery: https://www.datatables.net/examples/

【问题讨论】:

  • 你得到的错误是什么?另外,总是最好提供一些代码
  • 我已经使用 $config['page_query_string'] = TRUE;但在第二个链接 GET 变量将为空

标签: codeigniter pagination


【解决方案1】:

将 CodeIgniter 分页库与

结合使用

$config['page_query_string'] = TRUE;

并将您的搜索元素作为查询字符串传递。

那么您的网址将是:
http://localhost/project/controller/function?var=val&var1=val1&per_page=10

您可以通过以下方式获取 var、var1 和 per_page 的值:
$this->input->get('var')
$this->input->get('var1')
$this->input->get('per_page')

【讨论】:

    【解决方案2】:

    首先修改你的控制器如下

    function xyz()
     {
    $this->load->library('pagination');
    $config['base_url'] = "http://localhost/rainbow/admin/postList/xyz";
    $config['per_page'] = 10;
    $config['total_rows'] = $this->post_model->list_count();
    $config['uri_segment'] = 4;
    $config['page_query_string'] = TRUE;
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
    $this->pagination->initialize($config); 
    
    $data['lists']=$this->post_model->listing($config["per_page"], $page);
    $this->load->view('includes/header');
    $this->load->view('listing/listing_post',$data);
    $this->load->view('includes/footer');
     }
    

    正如我看到您的基本 url 并发现 uri 段 3 是您的控制器功能 xyz 并且因此分页不起作用。

    【讨论】:

      猜你喜欢
      • 2016-06-15
      • 2012-05-15
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      • 2012-05-14
      • 2017-12-20
      • 2013-10-28
      • 2012-12-03
      相关资源
      最近更新 更多