ZF-2218: Zend_View_Helper_Url and url encoding

Issue Type: Improvement Created: 2007-11-20T05:18:06.000+0000 Last Updated: 2008-02-26T12:55:59.000+0000 Status: Resolved Fix version(s): - 1.0.4 (26/Feb/08)

Reporter: Johannes Schill (johannes) Assignee: Michal Minicki (martel) Tags: - Zend_View

Related issues: - ZF-2297



Short summary: The parameters in Zend_View_Helper_Url are not url encoded when using the default parameters.

Long description: Today the parameters sent to Zend_View_Helper_Url are not url encoded so the programmer has to encode the parameters manually.

<pre class="highlight">
// route example:
// <a href="http://host/users/:user/">http://host/users/:user/</a>*
// name of the route: "user"

$name = 'John Doe';

$parameters = array(
    'name' => urlencode($name) // url encode manually

echo $this->url($parameters, 'user'); // echo url

This works fine. But when I go to the generated url (http://host/users/John+Doe) and want to see his statistics, i need to add a new parameter "show" with value "statistics". New url: http://host/users/John+Doe/show/statistics.

So, standing on http://host/users/John+Doe i wouldn't have to re-send the name-parameter (John Doe) since the helper should use the current parameters as default.

<pre class="highlight">
$parameters = array(
    'show' => 'statistics'

echo $this->url($parameters); // generates: "http://host/users/John Doe/show/statistics" - problem is the current parameters (John Doe) is not url encoded this time (note the missing +).

Note that "John Doe" is not url encoded this time. The only workaround I've found is to always pick up the current parameters, url encode using urlencode() and re-send them all to the helper.


Posted by Michal Minicki (martel) on 2007-11-22T12:22:46.000+0000

Commited to trunk. Thanks, Johannes.

Posted by Lee Saferite (lsaferite) on 2007-12-07T17:12:16.000+0000

This change breaks a lot of existing code by assuming that you WANT to encode parameters by default, contrary to prior behavior.

Posted by Gunter Sammet (guntersammet) on 2008-01-10T09:06:58.000+0000

Hi all: Been banging my head with this one. Some of my code broke after the last update to then current CVS. Ended up being changes to the url view helper. If you pass in parameters as null, they should be removed by the assemble method (undocumented feature but I assume it's intended). however, recent changes to urlencode the urlOptions broke this behaviour. the php function urlencode returns an empty string. So the route->assemble method doesn't know anymore that it was null. I suggest the following fix:

   if ($encode) {
       foreach ($urlOptions as $key => $option) {
           if(null === $option){
               $urlOptions[$key] = $option;
               $urlOptions[$key] = urlencode($option);

Unless there is an issue with unencoded null values (which I can't picture), this should solve the issue without causing any compatibility issues.

Anybody out there that can commit this fix? Thanks,


Posted by Michal Minicki (martel) on 2008-01-11T03:37:43.000+0000

Fixed with revision 7383. Thanks, Gunter.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.