Reputation: 21
I've been working on this CodeIngiter app for sometime now and unfortunately my Pagination links aren't beeing generated. I don't know the reason for that. I've tried many things but it just won't work.
Bare in mind that my Pagination library is on Autoload.
Here's my Pagination initialization function in my "MY_Controller" which is loaded by default on every page:
<?php
public function init_pagination($uri,$total_rows,$per_page=5){
$config['per_page'] = $per_page;
$config['base_url'] = base_url().$uri;
$config['total_rows'] = intval($total_rows);
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$this->pagination->initialize($config);
$config['links'] = $this->pagination->create_links();
return $config;
}?>
And here's my code in my Blog controller which calls this function and gets the results back:
<?php $data['pagg'] = $this->init_pagination("articles/index", round(count($data['particles'])/5, 0, PHP_ROUND_HALF_UP),5);?>
Now my model functions are working perfectly with the $data['pagg'] variable. I'm using the results my pagination returns to me to set the limit and offset on my Model functions. So I already know that the function is working and is not empty. But when I try to print the links, nothing is returned back to me. Why is that? Am I missing something? Have I done anything wrong? Here's a var_dump of my $pagg:
array(21) { ["per_page"]=> int(5) ["base_url"]=> string(47) "url.com/blog/index" ["total_rows"]=> int(2) ["use_page_numbers"]=> bool(true) ["full_tag_open"]=> string(23) "" ["full_tag_close"]=> string(5) "" ["first_link"]=> string(5) "First" ["first_tag_open"]=> string(4) "
" ["first_tag_close"]=> string(5) "
" ["last_link"]=> string(4) "Last" ["last_tag_open"]=> string(4) "
" ["last_tag_close"]=> string(5) "
" ["cur_tag_open"]=> string(22) "
" ["cur_tag_close"]=> string(9) "
" ["num_tag_open"]=> string(4) "
" ["num_tag_close"]=> string(5) "
" ["next_tag_open"]=> string(4) "
" ["next_tag_close"]=> string(5) "
" ["prev_tag_open"]=> string(4) "
" ["prev_tag_close"]=> string(5) "
" ["links"]=> string(0) "" }
As you see, not only the 'links' array is empty but also the next, previous and other tags that I've generated in my controller are displayed as empty here. I'd be grateful if you can help me with this. Thanks in advance.
Upvotes: 1
Views: 1157
Reputation: 12132
The problem you are experiencing most likely has to do with the numbers you are inputting for :
$config['total_rows'] = "";
$config['per_page'] = "";
As a rule you need to make sure that per_page
should be, at least, one number more than the total_rows
. If not, the system will not register any links because you are telling the system that all your results should fit in the current page.
When creating pagination, take this into account:
Source: http://www.codeigniter.com/user_guide/libraries/pagination.html?highlight=pagination
Upvotes: 1