Browse Source

modified GetViewHelper to return urlencoded GET query params

master
Anton Grebnev 13 years ago
parent
commit
f6e119d372
  1. 9
      tests/view/helpers/GetViewHelperTest.php
  2. 4
      view/helpers/GetViewHelper.php

9
tests/view/helpers/GetViewHelperTest.php

@ -69,4 +69,13 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
$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);
}
} }

4
view/helpers/GetViewHelper.php

@ -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;
} }
Loading…
Cancel
Save