【发布时间】:2014-10-22 04:52:37
【问题描述】:
我有一个分页类,它适用于像
这样的 urlhttp://localmachine/c/category-name
分页链接看起来像
http://localmachine/c/category-name/page-2
但如果我向基本网址添加另一个参数,例如:
http://localmachine/c/category-name/brand-Coca+Cola
分页链接将是
http://localmachine/brand/Coca+Cola/c/category-name/page-2
如何解决这个问题以显示分页链接
http://localmachine/c/category-name/brand/Coca+Cola/page-2
这是显示分页链接的分页函数。
function buildTrail($param = ""){
if(is_array($param)){
foreach($param as $a => $b){
if($a != "page"){
$url .= $a . "/" . urlencode($b).'/';
}else{
$url .= '';
}
}
} else {
$url = $param;
}
//$location = basename($_SERVER['REQUEST_URI']);
$trail = "";
if($this->getPages() > 1){
if($this->getFrom() > 1){
$trail .= "<a href='" . WEBSITE . "/". $url . "page-" . $this->getPrevious() . "'>«</a>\n ";
}
if($this->getFrom() < 10 && $this->getPages() > 10){
for ($i = 1; $i <= 10; $i++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/". $url . "page-" . $i . "'>" . $i . "</a>\n ";
}
} elseif($this->getFrom() < 10 && $this->getPages() < 10){
for ($i = 1; $i <= $this->getPages(); $i++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/". $url . "page-" . $i . "'>" . $i . "</a>\n ";
}
}elseif ($this->getFrom() >= 10 && $this->getFrom() <= ($this->getPages() - 5) ){
for ($i = ($this->getFrom() - 5); $i <= ($this->getFrom() + 5); $i ++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/". $url . "page-" . $i . "'>" . $i . "</a>\n ";
}
} else {
for ($i = ($this->getPages() - 9); $i <= $this->getPages(); $i ++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/". $url . "page-" . $i . "'>" . $i . "</a>\n ";
}
}
if($this->getFrom() < $this->getPages()){
$trail .= "<a href='" . WEBSITE . "/". $url . "page-" . $this->getNext() . "'>»</a>\n ";
}
}
return $trail;
}
【问题讨论】:
-
检查你在 $_GET 变量中得到的参数
标签: php html mysql pdo pagination