[英]CodeIgniter Pagination links format
我正在使用codeigniter的默认分页
< 1 2 3 4 >
但是我想用这种格式
< 1-10 11-20 21-30 >
有任何想法吗?
好问题:您需要将代码system/CI_Pagination.php
库扩展到application/library/MY_Pagination.php
@Dan的数学计算很好,设置到CI
分页库,见下文
1)创建文件到application/library/MY_Pagination.php
有关Create Library的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) 点击这里
注意我使用了最新的核心文件,因此请在当前文件中使用修改
做一些简单的数学调整,例如,如果$x = 1
而不是页面1是$ x第1页是:
<?php echo $x.'-'.($x * 10); ?>
第2页及以上是:
<?php
$x++;
echo (($x)*10)-10)+1.'-'.($x * 10);
?>
每个显示器的$x++
计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.