CodeIgniter修改分页的样式和内容
CodeIgniter中自带的分页办法,如果是第2页,就没有首页出现了。
一般情况下,页面的好看、方便,都需要任何时候都有首页、尾页出现。
例如:
首页 上一页 12345 下一页 尾页
现在我要任何时候都要出现:
首页 上一页 下一页 尾页
需要修改源文件Pagination.php 在system的libraries文件夹中。
一、修改first
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /*这个是原来的写法,现在修改一下 // Render the "First" link if ($this->cur_page > ($this->num_links + 1)) { $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close; } */ // Render the "First" link 新增,不是首页都一直显示,而且有超链接 if ($this->cur_page > 1) { $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close; } // Render the "First" link 如果是首页,同样显示,但是没有超链接功能 if ($this->cur_page == 1) { $output .= $this->first_tag_open.$this->first_link.$this->first_tag_close; } |
二、修改previous
1 2 3 4 5 6 7 | // Render the "previous" link 注意:这里是新增不是替换原来的啊。如果为第一页的时候,同样显示上一页标签,但是没有超链接 if ($this->cur_page == 1) { $i = $uri_page_number - $this->per_page; if ($i == 0) $i = ''; $output .= $this->prev_tag_open.$this->prev_link.$this->prev_tag_close; } |
三、修改next
1 2 3 4 5 | // Render the "next" link 注意:这里是新增不是替换原来的啊。如果是最后一页,同样显示,只是没有超链接 if ($this->cur_page == $num_pages) { $output .= $this->next_tag_open.$this->next_link.$this->next_tag_close; } |
四、修改Last
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /*这个是原来的写法,这里需要替换哦。 // Render the "Last" link if (($this->cur_page + $this->num_links) < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close; } */ // Render the "Last" link 如果不是最后一页,同样显示 if ($this->cur_page < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close; } // Render the "Last" link 如果是最后一页,同样显示,但是没有超链接 if ($this->cur_page == $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); $output .= $this->last_tag_open.$this->last_link.$this->last_tag_close; } |
CodeIgniter基本配置信息在config.php文件详细说明 php数组中删除元素之重新索引的三种方法
Pagination.php 在哪里
system的libraries文件夹中。