/** *输出分页 */ public function show() { if ($this->totalRows == 0) { return ''; } $nowCoolPage = ceil($this->nowPage / $this->barShowPage); $delimiter = Config::get('url_pathinfo_depr'); $params = array_merge($this->param, array($this->pageShowVarName => '__PAGE__')); $paramsString = ''; foreach ($params as $key => $val) { $paramsString .= $key . '/' . $val; } if ($this->url) { $url = rtrim(Response::Url($this->url . '/' . $paramsString, false), $delimiter); } else { $url = Route::$urlParams; $url['path'] = trim($url['path'], '\\'); unset($url['root']); $url = rtrim(Response::Url(implode('/', $url) . '/' . $paramsString, false), $delimiter); } $upRow = $this->nowPage - 1; $downRow = $this->nowPage + 1; $upPage = $upRow > 0 ? '<li><a href = "' . str_replace('__PAGE__', $upRow, $url) . '">' . $this->config['prev'] . '</a></li>' : ''; $downPage = $downRow <= $this->totalPages ? '<li><a href="' . str_replace('__PAGE__', $downRow, $url) . '">' . $this->config['next'] . '</a></li>' : ''; // << < > >> if ($nowCoolPage == 1) { $theFirst = $prePage = ''; } else { $preRow = $this->nowPage - $this->barShowPage; $prePage = '<li><a href="' . str_replace('__PAGE__', $preRow, $url) . '">上' . $this->barShowPage . '页</a></li>'; $theFirst = '<li><a href="' . str_replace('__PAGE__', 1, $url) . '">' . $this->config['first'] . '</a></li>'; } if ($nowCoolPage == $this->coolPages) { $nextPage = $theEnd = ''; } else { $nextRow = $this->nowPage + $this->barShowPage; $theEndRow = $this->totalPages; $nextPage = '<li><a href="' . str_replace('__PAGE__', $nextRow, $url) . '">下' . $this->barShowPage . '页</a></li>'; $theEnd = '<li><a href="' . str_replace('__PAGE__', $theEndRow, $url) . '">' . $this->config['last'] . '</a></li>'; } //1 2 3 4 5 $linkPage = ''; for ($i = 1; $i <= $this->barShowPage; $i++) { $page = ($nowCoolPage - 1) * $this->barShowPage + $i; if ($page != $this->nowPage) { if ($page <= $this->totalPages) { $linkPage .= ' <li><a href="' . str_replace('__PAGE__', $page, $url) . '"> ' . $page . ' </a></li>'; } else { break; } } else { if ($this->totalPages != 1) { $linkPage .= ' <li class="active"><a>' . $page . '</a></li>'; } } } $pageStr = str_replace(array('%header%', '%nowPage%', '%totalRow%', '%totalPage%', '%upPage%', '%downPage%', '%first%', '%prePage%', '%linkPage%', '%nextPage%', '%end%'), array($this->config['header'], $this->nowPage, $this->totalRows, $this->totalPages, $upPage, $downPage, $theFirst, $prePage, $linkPage, $nextPage, $theEnd), $this->config['theme']); return '<ul>' . $pageStr . '</ul>'; }
/** *输出分页 */ public function show() { if ($this->totalRows == 0) { return ''; } $p = $this->varPage; $nowCoolPage = ceil($this->nowPage / $this->rollPage); $depr = \Cml\Config::get('url_pathinfo_depr'); if ($this->url) { $url = rtrim(\Cml\Http\Response::Url($this->url . '/__PAGE__', $this->param, false), $depr); } else { $addUrl = \Cml\Config::get('APP_MODULE') ? CML_MODULE_NAME . '/' : ''; $this->param = array_merge($this->param, array($p => '__PAGE__')); $url = rtrim(\Cml\Http\Response::Url($addUrl . Route::$urlParams['controller'] . '/' . Route::$urlParams['action'], $this->param, false), $depr); } $upRow = $this->nowPage - 1; $downRow = $this->nowPage + 1; $upPage = $upRow > 0 ? '<li><a href = "' . str_replace('__PAGE__', $upRow, $url) . '">' . $this->config['prev'] . '</a></li>' : ''; $downPage = $downRow <= $this->totalPages ? '<li><a href="' . str_replace('__PAGE__', $downRow, $url) . '">' . $this->config['next'] . '</a></li>' : ''; // << < > >> if ($nowCoolPage == 1) { $theFirst = $prePage = ''; } else { $preRow = $this->nowPage - $this->rollPage; $prePage = '<li><a href="' . str_replace('__PAGE__', $preRow, $url) . '">上' . $this->rollPage . '页</a></li>'; $theFirst = '<li><a href="' . str_replace('__PAGE__', 1, $url) . '">' . $this->config['first'] . '</a></li>'; } if ($nowCoolPage == $this->coolPages) { $nextPage = $theEnd = ''; } else { $nextRow = $this->nowPage + $this->rollPage; $theEndRow = $this->totalPages; $nextPage = '<li><a href="' . str_replace('__PAGE__', $nextRow, $url) . '">下' . $this->rollPage . '页</a></li>'; $theEnd = '<li><a href="' . str_replace('__PAGE__', $theEndRow, $url) . '">' . $this->config['last'] . '</a></li>'; } //1 2 3 4 5 $linkPage = ''; for ($i = 1; $i <= $this->rollPage; $i++) { $page = ($nowCoolPage - 1) * $this->rollPage + $i; if ($page != $this->nowPage) { if ($page <= $this->totalPages) { $linkPage .= ' <li><a href="' . str_replace('__PAGE__', $page, $url) . '"> ' . $page . ' </a></li>'; } else { break; } } else { if ($this->totalPages != 1) { $linkPage .= ' <li class="active"><a>' . $page . '</a></li>'; } } } $pageStr = str_replace(array('%header%', '%nowPage%', '%totalRow%', '%totalPage%', '%upPage%', '%downPage%', '%first%', '%prePage%', '%linkPage%', '%nextPage%', '%end%'), array($this->config['header'], $this->nowPage, $this->totalRows, $this->totalPages, $upPage, $downPage, $theFirst, $prePage, $linkPage, $nextPage, $theEnd), $this->config['theme']); return '<ul>' . $pageStr . '</ul>'; }