0
我有一個帶有buildTrail功能的分頁類來顯示頁碼。使用過濾器時的分頁問題
對於搜索數據庫,這個類是偉大的工作。
如果我在尋找「英特爾」,第二頁的鏈接將是"http://localhost/search/intel/pg/2".
問題occures當我嘗試過濾結果.EX:「http://localhost/search/intel/type/ssd
」所以分頁鏈接將顯示:前「http://localhost/search/intel/type/ssd/intel/type/ssd/pg/2
」
function buildTrail($param = ""){
// $cur_page = basename($_SERVER['PHP_SELF']);
$link = $_SERVER['REQUEST_URI'];
$link_array = explode('/', $link);
//$count = count($link_array);
$pagename = $link_array[1];
// echo $magename;
if(is_array($param)){
foreach($param as $a => $b){
if($a != "page"){
$url .= $pagename."/".$b;
}
}
} else {
$url = $param;
}
$trail = "";
if($this->getPages() > 1){
if($this->getFrom() > 1){
$trail .= "<a href='" . WEBSITE . "/". $url . "/pg/" . $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."/pg/" . $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."/pg/" . $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."/pg/" . $i ."'>" . $i . "</a>\n ";
}
} else {
for ($i = ($this->getPages() - 10); $i <= $this->getPages(); $i ++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/".$url."/pg/" . $i ."'>" . $i . "</a>\n ";
}
}
if($this->getFrom() < $this->getPages()){
$trail .= "<a href='" . WEBSITE . "/".$url."/pg/" . $this->getNext()."'>»</a>\n ";
}
}
return $trail;
}
驗證是,在我看來,在成爲一個優秀的程序員的第一步。 –