【问题标题】:Codeigniter - pagination - number links to showCodeigniter - 分页 - 要显示的数字链接
【发布时间】:2013-05-03 15:02:03
【问题描述】:

我已经使用以下配置实现了分页

$config['page_query_string'] = TRUE;
$config['base_url'] = base_url()."jobs/?job=".$_GET['job']."&location=".$_GET['location'];
$config['total_rows'] = $totalCount;
$config['per_page'] = 10; 
$config['num_links']=15;
$this->pagination->initialize($config); 

这个分页很好,数字显示从 1 到 16。现在当我点击第 16 页时,它显示数字从 1 到 32,依此类推。 所以它增加了页面链接的数量,而不是从队列的开头删除。

这里哪里出错了?

【问题讨论】:

  • 我在上面的共享代码中没有看到任何错误。如果您甚至可以共享您使用 create_links 函数的视图部分,那将很有用

标签: php codeigniter pagination


【解决方案1】:

我也遇到了同样的问题。我认为您的代码没有任何错误。我认为它的 codeigniter 分页类问题。

我通过更改 systems/libraries/Pagination.php 文件解决了这个问题。

$start  = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;

$end    = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;

在上面两行注释并添加以下行。

$start  = ($this->cur_page >= $this->num_links) ? $this->cur_page - (((int)($this->num_links/2))-1) : 1;

$end    = ($this->cur_page >= $this->num_links) ? $this->cur_page + (int)($this->num_links/2) :$this->num_links;

if($end > $num_pages){
    $end = $num_pages;
}

所以首先它会告诉你

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

当你点击 15 页链接时,它会显示给你

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

当你点击16页链接时,它会显示给你

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

【讨论】:

  • HI HBhadra 我们可以在不编辑系统库的情况下做到这一点。类似于覆盖库的东西。如果可能,请在下面添加一个答案,这将是一个很好的帮助
【解决方案2】:

这里没有错误,我只是建议你:

$config['num_links']=15;

设置你想显示多少个链接,如果它们是15,,你会看到例如:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 

then -> 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

等等……

【讨论】:

    猜你喜欢
    • 2017-10-18
    • 2017-12-01
    • 2013-04-07
    • 2023-03-03
    • 2020-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多