PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » Pager » Bug #1904

Pager drops GET values although append = true

Details

Submitted2004-07-17 16:00 UTC
Fromlisten at scroogie dot de
Assignedquipo
StatusClosed
PackagePager
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-07-17 16:00 UTC] listen at scroogie dot de

Description:
------------
The append-option will not carry on Array Values given as GET Parameters. The code in common.php just overwrites the same array-element with the different values, resulting in having just the last value saved.

Possible solution could look like this:

function _getLinksUrl() {
// Sort out query string to prevent messy urls
$querystring = array();
$qs = array();
if (!empty($_SERVER['QUERY_STRING'])) {
$qs = explode('&', str_replace('&', '&', $_SERVER['QUERY_STRING']));
for ($i = 0, $cnt = count($qs); $i < $cnt; $i++) {
if(strstr($qs[$i], '=') !== false){ // check first if exist a pair
list($name, $value) = explode('=', $qs[$i]);
if ($name != $this->_urlVar) {
if (isset($qs[$name])) {
if (is_array($qs[$name])) {
$qs[$name][] = $value;
} else {
$qs[$name] = array($qs[$name], $value);
}
} else {
$qs[$name] = $value;
}
}
} else {
$qs[$qs[$i]] = '';
}
unset($qs[$i]);
}
}

foreach ($qs as $name => $value) {
if (is_array($value)) {
foreach ($value as $v) {
$querystring[] = $name . '=' . $v;
}
} else {
$querystring[] = $name . '=' . $value;
}
}
if (is_array($this->_extraVars)) {
foreach ($this->_extraVars as $name => $value) {
$querystring[] = $name . '=' . $value;
}
}

return '?' . implode('&', $querystring) . (!empty($querystring) ? '&' : '') . $this->_urlVar .'=';
}

Reproduce code:
---------------
Just set the append option to true in the options array passed to the constructor, and try passing an array like

site.php?foo[]=1&foo[]=2&foo[]=3

Pager will just pass foo[]=3 to the next page.
Code-Change is necessary in common.php in method _getLinksUrl().

[2004-07-18 11:12 UTC] listen at scroogie dot de

Patch works perfectly in my case.

Thanks for the quick fix, keep up the good work