先贴上thinkphp分页类代码,说明一下,我这个分页类是thinkphp3.2版本的。
'共 %total_row% 条记录', 'prev' => ' '>>', 'first' => '1...', 'last' => '...%total_page%', 'theme' => '%first% %up_page% %link_page% %down_page% %end%', ); /** * 架构函数 * @param array $totalrows 总的记录数 * @param array $listrows 每页显示记录数 * @param array $parameter 分页跳转的参数 */ public function __construct($totalrows, $listrows=20, $parameter = array()) { c('var_page') && $this->p = c('var_page'); //设置分页参数名称 /* 基础设置 */ $this->totalrows = $totalrows; //设置总记录数 $this->listrows = $listrows; //设置每页显示行数 $this->parameter = empty($parameter) ? $_get : $parameter; $this->nowpage = empty($_get[$this->p]) ? 1 : intval($_get[$this->p]); $this->nowpage = $this->nowpage>0 ? $this->nowpage : 1; $this->firstrow = $this->listrows * ($this->nowpage - 1); } /** * 定制分页链接设置 * @param string $name 设置名称 * @param string $value 设置值 */ public function setconfig($name,$value) { if(isset($this->config[$name])) { $this->config[$name] = $value; } } /** * 生成链接url * @param integer $page 页码 * @return string */ private function url($page){ return str_replace(urlencode('[page]'), $page, $this->url); } /** * 组装分页链接 * @return string */ public function show() { if(0 == $this->totalrows) return ''; /* 生成url */ $this->parameter[$this->p] = '[page]'; $this->url = u(action_name, $this->parameter); /* 计算分页信息 */ $this->totalpages = ceil($this->totalrows / $this->listrows); //总页数 if(!empty($this->totalpages) && $this->nowpage > $this->totalpages) { $this->nowpage = $this->totalpages; } /* 计算分页临时变量 */ $now_cool_page = $this->rollpage/2; $now_cool_page_ceil = ceil($now_cool_page); $this->lastsuffix && $this->config['last'] = $this->totalpages; //上一页 $up_row = $this->nowpage - 1; $up_page = $up_row > 0 ? 'url(%24up_row)%20.%20'>' . $this->config['prev'] . '' : ''; //下一页 $down_row = $this->nowpage + 1; $down_page = ($down_row totalpages) ? 'url(%24down_row)%20.%20'>' . $this->config['next'] . '' : ''; //第一页 $the_first = ''; if($this->totalpages > $this->rollpage && ($this->nowpage - $now_cool_page) >= 1){ $the_first = 'url(1)%20.%20'>' . $this->config['first'] . ''; } //最后一页 $the_end = ''; if($this->totalpages > $this->rollpage && ($this->nowpage + $now_cool_page) totalpages){ $the_end = 'url(%24this->totalpages)%20.%20'>' . $this->config['last'] . ''; } //数字连接 $link_page = ; for($i = 1; $i rollpage; $i++){ if(($this->nowpage - $now_cool_page) nowpage + $now_cool_page - 1) >= $this->totalpages){ $page = $this->totalpages - $this->rollpage + $i; }else{ $page = $this->nowpage - $now_cool_page_ceil + $i; } if($page > 0 && $page != $this->nowpage){ if($page totalpages){ $link_page .= 'url(%24page)%20.%20'>' . $page . ''; }else{ break; } }else{ if($page > 0 && $this->totalpages != 1){ $link_page .= '' . $page . ''; } } } //替换分页内容 $page_str = str_replace( array('%header%', '%now_page%', '%up_page%', '%down_page%', '%first%', '%link_page%', '%end%', '%total_row%', '%total_page%'), array($this->config['header'], $this->nowpage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalrows, $this->totalpages), $this->config['theme']); return {$page_str}
; }}
1. 将
private $url = ''; //当前链接url
代码修改为:
public $url = ''; //当前链接url
2. 将
$this->parameter[$this->p] = '[page]';$this->url = u(action_name, $this->parameter);
修改为
if (empty($this->url)) { $this->parameter[$this->p] = '[page]'; $this->url = u(action_name, $this->parameter);}else { $depr = c('url_pathinfo_depr'); $this->url = rtrim(u('/'.$this->url,'',false),$depr).$depr.urlencode('[page]').'.html';}
然后在调用分页类的时候给$page->url赋值,具体赋值情况要根据你所写的伪静态来设定。