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, [$this->pageShowVarName => '__PAGE__']);
$paramsString = '';
foreach ($params as $key => $val) {
$paramsString == '' || ($paramsString .= '/');
$paramsString .= $key . '/' . $val;
}
if ($this->url) {
$url = rtrim(Response::url($this->url . '/' . $paramsString, false), $delimiter);
} else {
$url = rtrim(Response::url(Cml::getContainer()->make('cml_route')->getFullPathNotContainSubDir() . '/' . $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(['%header%', '%nowPage%', '%totalRow%', '%totalPage%', '%upPage%', '%downPage%', '%first%', '%prePage%', '%linkPage%', '%nextPage%', '%end%'], [$this->config['header'], $this->nowPage, $this->totalRows, $this->totalPages, $upPage, $downPage, $theFirst, $prePage, $linkPage, $nextPage, $theEnd], $this->config['theme']);
return '<ul>' . $pageStr . '</ul>';
}