Reputation: 57
my pagination problem still continue ;
I just making pagination in simple stuff :
$config['base_url'] = site_url('admin/index/page/');
$this->load->database();
$config['total_rows'] = $this->db->count_all('sms');
$config['per_page'] = 20;
$offset = $this->uri->segment(4, 0);
$this->pagination->initialize($config)
And my view page has this command for view pagination :
<?php echo $this->pagination->create_links(); ?>
And after more than 20 rows , pagination starts to paging the list, but html output shows like this :
As in view , First Page Number 1 does not have link either jumping next page , there is no link on page number 1. Just its on strong .
My second problem is : I have just 30 record but CI pagination creates 3rd page which is coming with empty rows !
I am not sure why some Class ( specially pagination makes so much trouble to users ? ) If i need to pay something ( maybe hidden licence? ) for get away from trouble instead of using simple pagination class without loosing so much time for searching issue on internet , I am ready for it !
Upvotes: 2
Views: 7130
Reputation: 1665
I was very mad because of this pagination problem and I was studying the source code of the pagination library and I saw this -- var $uri_segment = 3; The default of the pagination library uses the 3rd uri segment, in your case and in my case we wanted to use the 4th uri segment. To suit our needs change this code:
$config['base_url'] = site_url('admin/index/page/');
$this->load->database();
$config['total_rows'] = $this->db->count_all('sms');
$config['per_page'] = 20;
$offset = $this->uri->segment(4, 0);
$this->pagination->initialize($config)
TO
$config['base_url'] = site_url('admin/index/page/');
$this->load->database();
$config['total_rows'] = $this->db->count_all('sms');
$config['per_page'] = 20;
$offset = $this->uri->segment(4, 0);
$config['uri_segment'] = 4; // add this line to override the default
$this->pagination->initialize($config)
Kindly post back here if this will solve your problem or if the problem still exists so I can help :)
Nwei this is not in the pagination class documentation. I hope this will be added to the docs because I'm seeing many developers having a hard time with the pagination class.
Upvotes: 12
Reputation: 1665
I was also having the same issue in pagination when using segment number 4. I solved it by using segment number 3. Thats also my problem because I really need to use segment number 4 But Oh well it has bug. I hope this can be solved ASAP. Or if u really need to fix this issue now u can try to fork the source code of pagination class.
Upvotes: 0
Reputation: 926
If you are familiar with how pagination works, then you should be aware that pagination does not add a link tag to the current page. So I'm not sure what you're asking in regards to "pagination class does not create 1 page link".
Also, I don't see where you're offset is being used within the pagination functionality. It seems like you set it but you don't use it. This can cause an incorrect pagination result which I assume is why you get more pagination links than you expect.
$offset = $this->uri->segment(4, 0);
$this->pagination->initialize($config);
One way to change the markup for the "current page" link is 'Customizing the "Current Page" Link'
$config['cur_tag_open'] = '<a href="#">';
The opening tag for the "current" link.
$config['cur_tag_close'] = '</a>';
The closing tag for the "current" link.
The other option is to dive into the pagination class and remove the functionality it has for not adding a link to the current page.
Really, if you're on the current page, it doesn't add any benefit to link to the same page you're already on which I'm assuming is the reason the current page doesn't have a link. If you went to page 2 then the 2 would be disabled. Hope that makes some sense.
Upvotes: 1
Reputation: 8012
No, there no need to pay anything ...CI pagination works perfectly ..you see this library http://codeigniter.com/user_guide/libraries/pagination.html
make sure your $config['total_rows'] = $this->db->count_all('sms');
this code is working correct and providing the correct number of rows and also i would like to suggest use ..$config['uri_segment'] = 3;
or $config['uri_segment'] = 4; depend on your uri
rather than using $offset = $this->uri->segment(4, 0);
Hofefully these few change will work for you....
Upvotes: 0