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

@ -68,5 +68,14 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
$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);
}
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)){
$result = array();
foreach ($value as $key => $val) {
$result[] = $name . '[' . $key . ']=' . $val;
$result[] = $name . '[' . $key . ']=' . urlencode($val);
}
$result = implode('&', $result);
} else {
$result = $name . '=' . $value;
$result = $name . '=' . urlencode($value);
}
return $result;
}
Loading…
Cancel
Save