简体   繁体   English

使用CodeIgniter分页不起作用

[英]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. 我正在尝试使用CodeIgniter进行分页,但是它不起作用,链接会随心所欲地显示,而且我不明白这是怎么回事。

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: 当我将per_page设置为1时,这是我导航到每个页面时发生的情况:

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

And if I set use_page_numbers to true this happens: 如果我将use_page_numbers设置为true,则会发生这种情况:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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