Welcome Guest, Not a member yet? Register   Sign In
Extra Pagination Page Number
#1

[eluser]Unknown[/eluser]
Hi ,
When I'm using pagination with $config['use_page_numbers'] = TRUE; and ci makes pagination links, it put 1 extra page number!!
for example i have 38 rows!and per_page is 10, ci makes 1 2 3 4 5 (the Five is Extra!)

this is my code:
Code:
$msg = $this->session->flashdata('msg');
  $this->load->model('admin_panel','ap');
  $this->ap->alterTable('pm','id','DESC');
  $this->load->library('pagination');
  $config['base_url'] = base_url() . 'admin/mng_posts/';
  $config['total_rows'] = $this->db->get_where('content',array('static' => '0'))->num_rows();
  $config['num_links'] = 5;
  $config['per_page'] = 10;
  $config['uri_segment'] = 3;
  $config['full_tag_open'] = '<div id="pagintion">';
  $config['full_tag_close'] = '</div>';
  $config['use_page_numbers'] = TRUE;
  $page_number = $this->uri->segment(3);
  $offset = $config['per_page'] * $page_number;
  $posts = $this->ap->pagenated('content', array('static' => '0'),$config['per_page'], $offset);;
  $this->pagination->initialize($config);
  $data = array('posts' => $posts, 'msg' => $msg);
  $this->load->view('admin/mng_posts',$data);
#2

[eluser]Unknown[/eluser]
i think i found the bug!
the cause is:
{
Code:
if ($this->use_page_numbers)
  {
   $base_page = 1;
  }
}
i just add a =-1 to this if statement and it works correctly!

Code:
if ($this->use_page_numbers)
  {
   $num_pages -=1;
   $base_page = 1;
  }

AND this is a very first part of create_link function in pagination library in system->library folder that should change!

Code:
function create_links()
{
  // If our item count or per-page total is zero there is no need to continue.
  if ($this->total_rows == 0 OR $this->per_page == 0)
  {
   return '';
  }

  // Calculate the total number of pages
  $num_pages = ceil($this->total_rows / $this->per_page);

  // Is there only one page? Hm... nothing more to do here then.
  if ($num_pages == 1)
  {
   return '';
  }

  // Set the base page index for starting page number
  if ($this->use_page_numbers)
  {
   $num_pages -=1;
   $base_page = 1;
  }
  else
  {
   $base_page = 0;
  }




Theme © iAndrew 2016 - Forum software by © MyBB