简体   繁体   中英

Pagination with CodeIgniter won't work

I am trying to use pagination with CodeIgniter but it doesn't work, links are showed as it pleases and I don't understand what's wrong.

The buttons are shown properly (well "last" and "first" buttons are only shown in these pages, it'd be nice to see them in every page) but the pages generated are a mess.

I have the following data in my table:

text1
text2
text3
text4

When I set per_page to one this is what happens when I navigate to each page:

page 1: text1
page 2: text3
page 3: text4
page 4: text4

And if I set use_page_numbers to true this happens:

page 1: text1
page 2: text4
page 3: text4
page 4: invalid page (well, redirected because no data from de DB was selected)

I hope I could find some help. I truly don't understand what's going on, and the manual doesn't say much.

$config['base_url'] = site_url('foro/lista/'.$pais.'/'.$ciudad);
$config['total_rows'] = $this->foro_model->numero_de_posts($this->util->ciudad_id($ciudad));
$config['per_page'] = 1;
$config['uri_segment'] = 5;
$config['display_pages'] = TRUE;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = FALSE;
$config['full_tag_open'] = '<div class="paginacion-container">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = '<span class="paginacion icon icon-step-backward"></span>';
$config['first_tag_open'] = '';
$config['first_tag_close'] = '';
$config['last_link'] = '<span class="paginacion icon icon-step-forward"></span>';
$config['last_tag_open'] = '';
$config['last_tag_close'] = '';
$config['next_link'] = '<span class="paginacion icon icon-chevron-right">';
$config['next_tag_open'] = '';
$config['next_tag_close'] = '';
$config['prev_link'] = '<span class="paginacion icon icon-chevron-left"></span>';
$config['prev_tag_open'] = '';
$config['prev_tag_close'] = '';
$config['cur_tag_open'] = '<span class="paginacion-cur"><b>';
$config['cur_tag_close'] = '</b></span>';
$config['num_tag_open'] = '<span class="paginacion-num"><b>';
$config['num_tag_close'] = '</b></span>';
$config['anchor_class'] = 'pag-row ';

$this->pagination->initialize($config);

You can try this:

Here is a simple example showing how to create pagination in one of your controller functions:

$this->load->library('pagination');

$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20; 

$this->pagination->initialize($config); 

echo $this->pagination->create_links();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM