PHP Classes

fix for URL problems

Recommend this page to a friend!

      Paginator  >  All threads  >  fix for URL problems  >  (Un) Subscribe thread alerts  
Subject:fix for URL problems
Summary:fix for problem with keeping additional URL params when paging
Messages:1
Author:mike dee
Date:2006-09-07 00:59:25
 

  1. fix for URL problems   Reply   Report abuse  
Picture of mike dee mike dee - 2006-09-07 00:59:25
I guess you could call this a bug - if you had parameters within the URL that paginator was using they would be lost once you navigated off the main results page

I've updated the pagination.php file with the fix below that keeps the URL parameters intact

The code indents could use some beautification as well, its somewhat messy code to read

In paginator.php add the following method on or around line 160 (added mine after the getPageName() method):

// method that traps any user defined parameters to maintain them, and strips out the existing page param
function getQuerystring() {
$this->querystring = $_SERVER['QUERY_STRING'];
// strip out the old page info
// this is a hack to get the strpos function to return 1 vs 0 if the string page is found in the querystring var
// without adding the leading space if page is found it will return 0 which is eval'd as false. so moving it over 1 position by
// prepending a space will get strpos to eval to >0 or true if page is found.
// since page is always the first variable in the query string we can assume position 0 in the querystring variable
if (strpos(" " . $this->querystring, 'page=') > 0) {
$newpos = strpos($this->querystring, '&') + 1;
$len = strlen($this->querystring);
$this->querystring = substr($this->querystring, $newpos, ($len-$newpos));
}
return $this->querystring;
}

in the paginator_html.php file I've updated most of the method, so the following is a direct replacement:

//outputs a link set like this Previous 1 2 3 4 5 6 Next
function previousNext() {
if($this->getPrevious()) {
echo "<a href=\"" . $this->getPageName() . "?page=" . $this->getPrevious() . "&" . $this->getQuerystring() . "\">Previous</a> ";
}
$links = $this->getLinkArr();

foreach($links as $link) {
if ($link == $this->getCurrent()) {
echo " $link ";
} else {
echo "<a href=\"" . $this->getPageName() . "?page=$link" . "&" . $this->getQuerystring() . "\">" . $link . "</a> ";
}
}

if($this->getNext()) {
echo "<a href=\"" . $this->getPageName() . "?page=" . $this->getNext() . "&" . $this->getQuerystring() . "\">Next</a> ";
}
}

its a nice little module that just needed abit of tweaking, I tried emailing the author but the email address bounced so I'm posting the fix here for others to use