如何在codeigniter中创建分页查询字符串

时间:2016-11-11 06:03:00

标签: codeigniter pagination

我的网址是这样的:

  

的myproject /搜索?S =一个

如何制作分页

这是我在控制器中的代码:

public function index()
    {
        $keyword = $this->input->get('s');
        $config['per_page']             = 2;
        $config['uri_segment']          = 2;
        $config['full_tag_open']        = '<nav class="pagination"><ul>';
        $config['full_tag_close']       = '</ul></nav>';
        $config['num_tag_open']         = '<li>';
        $config['num_tag_close']        = '</li>';
        $config['cur_tag_open']         = '<li class="active"><a href="'.site_url(uri_string()).'">';
        $config['cur_tag_close']        = '<span class="sr-only">(current)</span></a></li>';
        $config['prev_tag_open']        = '<li>';
        $config['prev_tag_close']       = '</li>';
        $config['next_tag_open']        = '<li>';
        $config['next_tag_close']       = '</li>';
        $config['first_link']           = '&laquo;';
        $config['prev_link']            = '&lsaquo;';
        $config['last_link']            = '&raquo;';
        $config['next_link']            = '&rsaquo;';
        $config['first_tag_open']       = '<li>';
        $config['first_tag_close']      = '</li>';
        $config['last_tag_open']        = '<li>';
        $config['last_tag_close']       = '</li>';
        $config['base_url']             = site_url('search');
        $config['total_rows']           = $this->m_home->count_search_produk($keyword);
        $this->pagination->initialize($config);
        $data['results']                = $this->m_home->search_produk($keyword, $config['per_page'], 0);
        $data['pagination']             = $this->pagination->create_links();        
        $data['total']                  = $this->m_home->count_search_produk($keyword);
        $this->theme->frontend('f_home/search', $data);
    }

在这一行: $ data ['results'] = $ this-&gt; m_home-&gt; search_produk($ keyword,$ config ['per_page'],0);

我设置偏移量0,我想使用uri_segment设置dinamicly,但不能正常工作,怎么做?

当我点击分页时,网址如下:

  

的myproject /搜索S = A&安培;页= 3

1 个答案:

答案 0 :(得分:0)

它运作良好

public function search()
    {
        $keyword = $this->input->get('s');
        $data['title']                  = 'Search Results';
        $config['per_page']         = 2;
        $config['uri_segment']          = 2;
        $config['full_tag_open']        = '<nav class="pagination"><ul>';
        $config['full_tag_close']       = '</ul></nav>';
        $config['num_tag_open']     = '<li>';
        $config['num_tag_close']        = '</li>';
        $config['cur_tag_open']     = '<li class="active"><a href="'.site_url(uri_string()).'">';
        $config['cur_tag_close']        = '<span class="sr-only">(current)</span></a></li>';
        $config['prev_tag_open']        = '<li>';
        $config['prev_tag_close']       = '</li>';
        $config['next_tag_open']        = '<li>';
        $config['next_tag_close']       = '</li>';
        $config['first_link']           = '&laquo;';
        $config['prev_link']            = '&lsaquo;';
        $config['last_link']            = '&raquo;';
        $config['next_link']            = '&rsaquo;';
        $config['first_tag_open']       = '<li>';
        $config['first_tag_close']      = '</li>';
        $config['last_tag_open']        = '<li>';
        $config['last_tag_close']       = '</li>';
        $config['page_query_string']    = TRUE;
        $config['query_string_segment']= 'page';
        $config['base_url']         = site_url('search?s='.$keyword);
        $config['total_rows']           = $this->m_home->count_search_produk($keyword);
        $this->pagination->initialize($config);
        $page = (empty($_GET['page'])) ? 0 : $_GET['page'];
        $data['results']                = $this->m_home->search_produk($keyword, $config['per_page'], $page);
        $data['pagination']         = $this->pagination->create_links();
        $data['total']                  = $this->m_home->count_search_produk($keyword);
        $this->theme->frontend('f_home/search', $data);
    }