currentPage = $currentPage; $this->totalResults = $totalResults; if(!is_null($key)) { $this->key = $key; } if(!is_null($resultsPerPage)) { $this->resultsPerPage = $resultsPerPage; } if(!is_null($target)) { $this->target = $target; } else { $this->target = $this->getCurrentURI(); } } protected function getCurrentURI() { return $_SERVER['REQUEST_URI']; } protected function replacePageVariable($uri, $pageNumber) { $pathInfo = parse_url($uri); if(array_key_exists('query', $pathInfo)) { $queryString = $pathInfo['query']; } else { $queryString = ''; } parse_str($queryString, $queryArray); $queryArray[$this->key] = $pageNumber; if($pageNumber == 1) { unset($queryArray[$this->key]); } $queryString = http_build_query($queryArray); $new = $pathInfo['path']; if($queryString != ''){ $new .= '?' . $queryString; } return $new; } protected function getMaxPages() { if($this->totalResults==0) { return 1; } $max = intval($this->totalResults / $this->resultsPerPage); if($this->totalResults % $this->resultsPerPage > 0) { $max++; } return intval($max); } public function paginate() { echo '