Codeigniter Pagination first page is always current page Codeigniter Pagination first page is always current page codeigniter codeigniter

Codeigniter Pagination first page is always current page


define cur_page and define controller like :

public function index($page=''){    //...    $page = ($page!='')? $page : 0;    $config["cur_page"] = $page;    //...}


Use this in your code, hope this will work-

if ($this->uri->segment(3) > 0) {     $offset = $this->uri->segment(3) * $config['per_page'] - $config['per_page']; } else {     $offset = $this->uri->segment(3); }


I've been working for about 6 hours to make CI pagination work as I expected, and I don't know if is the order of the config elements or just my browser joking with me.

Below is my configuration array for pagination to work properly.

As you can see this is normal code, but my problem was, when I rendered for the first time, my pagination view, all seems to be ok, but if $config['per_page'] = 10; was set to 10, when I clicked on 11 link of pagination links, link number 2 showed Cseguimiento/buscar_reportes/# and looks like current page was 2 not 11.

I was very tired and I started to change the order of $config array, and suddenly it worked. SO I preesnt it here.

$config['base_url'] = base_url().'Cseguimiento/buscar_reportes/';$config['uri_segment'] = 3;$config['use_page_numbers'] = TRUE;$config['first_link'] = FALSE;$config['last_link'] = FALSE;$config['next_link'] = '>';$config['prev_link'] = '<';$config["full_tag_open"] = '<ul class="pagination">';$config["full_tag_close"] = '</ul>';$config["first_tag_open"] = '<li>';$config["first_tag_close"] = '</li>';$config["last_tag_open"] = '<li>';$config["last_tag_close"] = '</li>';$config["next_tag_open"] = '<li>';$config["next_tag_close"] = '</li>';$config["prev_tag_open"] = "<li>";$config["prev_tag_close"] = "</li>";$config["cur_tag_open"] = "<li>";$config["cur_tag_close"] = "</li>";$config["num_tag_open"] = "<li>";$config["num_tag_close"] = "</li>";$config['total_rows'] = $this->mseguimiento->filas($fecha_inicio,$fecha_fin);$config['per_page'] = 10;$choice = $config["total_rows"] / $config["per_page"];$config["num_links"] = round($choice);$page = $config['uri_segment'] * $config['per_page'];$this->pagination->initialize($config);$offset = ($this->uri->segment(3)-1)*$config['per_page'];$output = array(    'pagination_link'  => $this->pagination->create_links(),    'lista_reportes'   => $this->mseguimiento->fetch_details($this->pagination->per_page, $offset,$fecha_inicio,$fecha_fin)    );