CodeIgniter分页链接格式

时间:2014-08-28 02:02:10

标签: php codeigniter pagination

我正在使用codeigniter的默认分页

< 1 2 3 4 >

但我想将其制作成这种格式

< 1-10 11-20 21-30 >

任何想法?

2 个答案:

答案 0 :(得分:2)

好问题:您需要将代码system/CI_Pagination.php扩展到application/library/MY_Pagination.php

@Dan的数学计算很好,设置到CI分页库,见下文

1)创建关于创建库

application/library/MY_Pagination.php more info文件

从自定义方法覆盖create_links()方法,见下文

create_links()方法

中的

修改代码部分

if ($this->cur_page === $loop){
    // Current page
    $output .= $this->cur_tag_open.($this->cur_page == 1 ? $loop : $loop*($this->per_page)+1).'-'.($loop * $this->per_page).$this->cur_tag_close;
}elseif ($i === $base_page){
 // First page
    $output .= $this->num_tag_open.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
               .((($loop)*($this->per_page) - $this->per_page)+1) .'-'. ($loop * $this->per_page).'</a>'
               .$this->num_tag_close;
}else{
     $append = $this->prefix.$i.$this->suffix;
     $output .= $this->num_tag_open.'<a href="'.$base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'
               .((($loop)*($this->per_page) - $this->per_page)+1) .'-'. ($loop * $this->per_page)
               .'</a>'.$this->num_tag_close;
}

完整 MY_Pagination.php 文件行号(577-592)click here

注意我使用了最新的核心文件,因此请在当前文件中使用修改

答案 1 :(得分:1)

做一些简单的数学调整,例如$x = 1

而不是页面1是$ x第1页是:

<?php echo $x.'-'.($x * 10); ?>

第2页及以上是:

<?php 
    $x++;
    echo (($x)*10)-10)+1.'-'.($x * 10);
?>

每个显示器的$x++计数。

相关问题