用户
 找回密码
 入住 CI 中国社区
搜索
查看: 16310|回复: 21
收起左侧

[分页] ci的分页修改

    [复制链接]
发表于 2010-1-2 15:27:05 | 显示全部楼层 |阅读模式
ci中自带的分页办法,如果是第2页,就没有首页出现了。。
一般情况下,页面的好看、方便,都需要任何时候都有首页、尾页出现。。
例如:
首页  上一页 12345 下一页 尾页
现在我要任何时候都要出现 首页  上一页   下一页 尾页
需要修改源文件Pagination.php 在system的libraries文件夹中

这个是first要修改的地方

  1. /*这个是原来的写法,现在修改一下
  2.   // Render the "First" link
  3.   if  ($this->cur_page > ($this->num_links + 1))
  4.   {
  5.    $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
  6.   }
  7.         */
  8.         // Render the "First" link 新增,不是首页都一直显示,而且有超链接
  9.   if  ($this->cur_page > 1)
  10.   {
  11.    $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
  12.   }
  13.         // Render the "First" link 如果是首页,同样显示,但是没有超链接功能
  14.   if  ($this->cur_page == 1)
  15.   {
  16.    $output .= $this->first_tag_open.$this->first_link.$this->first_tag_close;
  17.   }
复制代码
然后到previous,注意,这里是在原来的下面添加,不是修改原来的

  1. // Render the "previous" link 注意:这里是新增不是替换原来的啊。如果为第一页的时候,同样显示上一页标签,但是没有超链接
  2.   if  ($this->cur_page == 1)
  3.   {
  4.    $i = $uri_page_number - $this->per_page;
  5.    if ($i == 0) $i = '';
  6.    $output .= $this->prev_tag_open.$this->prev_link.$this->prev_tag_close;
  7.   }
复制代码
再到next,注意,这里是在原来的下面添加,不是修改原来的

  1. // Render the "next" link 注意:这里是新增不是替换原来的啊。如果是最后一页,同样显示,只是没有超链接
  2.   if ($this->cur_page == $num_pages)
  3.   {
  4.    $output .= $this->next_tag_open.$this->next_link.$this->next_tag_close;
  5.   }
复制代码
最后是last了。。
  1.   
  2. /*这个是原来的写法,这里需要替换哦。
  3.   // Render the "Last" link
  4.   if (($this->cur_page + $this->num_links) < $num_pages)
  5.   {
  6.    $i = (($num_pages * $this->per_page) - $this->per_page);
  7.    $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close;
  8.   }
  9.         */
  10.         
  11.         // Render the "Last" link 如果不是最后一页,同样显示
  12.   if ($this->cur_page < $num_pages)
  13.   {
  14.    $i = (($num_pages * $this->per_page) - $this->per_page);
  15.    $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close;
  16.   }
  17.         
  18.         // Render the "Last" link 如果是最后一页,同样显示,但是没有超链接
  19.   if ($this->cur_page == $num_pages)
  20.   {
  21.    $i = (($num_pages * $this->per_page) - $this->per_page);
  22.    $output .= $this->last_tag_open.$this->last_link.$this->last_tag_close;
  23.   }
复制代码
搞掂了。。注意备份原来文件啊。。觉得不合适就覆盖还原就可以了。。

评分

参与人数 1威望 +5 收起 理由
Hex + 5 原创内容

查看全部评分

发表于 2010-1-3 15:16:09 | 显示全部楼层
刚搜索就看见了,收藏
发表于 2010-1-9 11:06:43 | 显示全部楼层
正想改这个类实现这样的功能呢。。。
非常感谢!
发表于 2010-1-15 19:55:55 | 显示全部楼层
好东东
发表于 2010-1-17 00:46:09 | 显示全部楼层
CI 编程规范不建议直接修改system里的文件。
可以把复制一份放到application/library里然后改这个。
发表于 2010-1-21 17:23:35 | 显示全部楼层
我的神啊 我爱死你了
发表于 2010-2-24 09:08:08 | 显示全部楼层
不知道是你的ci版本问题还是怎么回事 你写的东西很蹊跷
完全找不到你说的这里改那里补
发表于 2010-2-24 18:00:54 | 显示全部楼层
我找到这些代码了……楼上的再仔细看看吧
发表于 2010-3-23 20:28:46 | 显示全部楼层
做个记号!
发表于 2010-4-4 15:36:57 | 显示全部楼层
顶一个

本版积分规则