0
votes

I am passing URL query string parameters to control from form but base URL I am giving my controller/method name here I have no idea how to pass query string also to base url.

results page url: http://localhost/Shop/products?category=10&subcategory=15

pagination showing links but when I click on next link page, URL showing like this http://localhost/Shop/products/&per_page=10

My Controller Code:

$config = array();
$config['page_query_string'] = TRUE;
$config["base_url"] = 'control/method/';
$config["total_rows"] = $this->model->record_count();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
//pagination style
$config['full_tag_open'] = '<ul>';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '&lt;';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&gt;';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="current"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '&lt;&lt;';
$config['last_link'] = '&gt;&gt;';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["productcount"] = $config["total_rows"];
$data["records"] = $this->model->fetch_products($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('admin/productlist', $data);
2
I have solved this issue with the help of this post. stackoverflow.com/questions/15231235/… - jack brone

2 Answers

0
votes

Try This --

Controller --

 public function blog()
    {
          $this->load->library('pagination');
          $total_row11 = $this->blogs_model->total_rows_count();
          $config = array();
          $config['base_url'] = base_url() . "blogs/blog";
          $config['total_rows'] = $total_row11;
          $config['per_page'] = 5;
          $config['cur_tag_open'] = '&nbsp;<a href="javascript:;">';
          $config['cur_tag_close'] = '</a>';
          $config['next_link'] = 'Next';
          $config['prev_link'] = 'Previous';
          $this->pagination->initialize($config);
          if($this->uri->segment(3)){
          $page = (int) ($this->uri->segment(3)) ;
          }
          else{
          $page = 0;
          }
          $data['all_blogs'] = $this->blogs_model->getAllBlogs($config['per_page'],$page);
          $str_links =  $this->pagination->create_links();
          $data['links'] = explode('&nbsp;',$str_links );
          $this->load->view('other/blogs/blogs',$data);
    }

In Model --

public function getAllBlogs($limit,$id)
        {
            $query = $this->db->query(" SELECT * FROM blogs ORDER BY blog_id DESC LIMIT $limit OFFSET $id ");
            if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
            $data[] = $row;
            }
            return $data;
            }
            return false;
        }
0
votes

Change your config's base_url, and add your custom query vars with php's http_build_query():

$query_vars = array('category' => 10, 'subcategory' = 15);
// Or:
$query_vars = array(
  'category' => $this->input->get('category'), 
  'subcategory' = $this->input->get('subcategory')
);
$config['base_url'] = 'control/method/?' . http_build_query($query_vars)

After CI will add the per_page var to the end.

In CI3, you have config item for this:

$config['reuse_query_string'] = TRUE;

Sidenote: http_build_query() is a php5 method.