modified GetViewHelper to return urlencoded GET query params
This commit is contained in:
@ -68,5 +68,14 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
|
|||||||
$result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six')));
|
$result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six')));
|
||||||
$this->assertSame('?a[one]=1&a[two]=2&b=c&c[five]=six', $result);
|
$this->assertSame('?a[one]=1&a[two]=2&b=c&c[five]=six', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetUrlencode()
|
||||||
|
{
|
||||||
|
$_GET['a'] = array('one' => 1, 'two' => 2);
|
||||||
|
$_GET['b'] = 'a';
|
||||||
|
$_GET['c'] = array('three' => 'four');
|
||||||
|
$result = $this->helper->get(array('b' => 'c d e', 'c' => array('five' => 'six seven')));
|
||||||
|
$this->assertSame('?a[one]=1&a[two]=2&b=c+d+e&c[five]=six+seven', $result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,11 @@ class GetViewHelper extends ViewHelper
|
|||||||
if (is_array($value)){
|
if (is_array($value)){
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($value as $key => $val) {
|
foreach ($value as $key => $val) {
|
||||||
$result[] = $name . '[' . $key . ']=' . $val;
|
$result[] = $name . '[' . $key . ']=' . urlencode($val);
|
||||||
}
|
}
|
||||||
$result = implode('&', $result);
|
$result = implode('&', $result);
|
||||||
} else {
|
} else {
|
||||||
$result = $name . '=' . $value;
|
$result = $name . '=' . urlencode($value);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user