ZF-8914: Specifying numeric parameter name for page link generates incorrect URL


Tested on 1.10.0beta and 1.10.0rc1

When trying to generate links like the following:

<a rel="nofollow" href="http://localhost/news/view/6/zf-1.10.0rc1-released">http://localhost/news/view/6/zf-1.10.0rc1-released</a>

Specifying the parameter '6' generates URLs as follows:

<a rel="nofollow" href="http://localhost/news/view/0/zf-1.10.0rc1-released">http://localhost/news/view/0/zf-1.10.0rc1-released</a>

Casting the parameter number to a string has no effect.


$pages = array( 'module' => 'default', 'controller' => 'news',
'action' => 'view', 'params' => array($item['id'] => 'zf-1.10.0rc1-released'), 'label' => 'zf-1.10.0rc1-released, 'route' => 'www-index', 'resource' => 'www', );

$entry = new Zend_Navigation_Page_Mvc($page); $container->addPage($entry);

Adding characters to the param, for example using...

<a rel="nofollow" href="http://localhost/news/view/-6-/zf-1.10.0rc1-released">http://localhost/news/view/&hellip;</a> as expected.


The problem is the assemble() methods in Zend_Controller_Router_* classes, it is due to the way PHP's array_merge function ( works.

Take this example:

[lloyd@veritas Zend]$ php -a Interactive shell

php > $arr1 = array(); php > $arr2 = array(1 => 'value 1', 'page' => 'page 1'); php > $merged = array_merge($arr1, $arr2); php > var_dump($merged); array(2) { [0]=> string(7) "value 1" ["page"]=> string(6) "page 1" }

You'd expect to get array(2) { '1' => 'value 1', 'page' => 'page 1', } or similar back. Casting the array keys to strings does not help.

This means that it is not possible to use the routers to generate URIs with a numerical value using the present system.

One approach to fix this issue would be to create custom array_merge functionality which keeps the array key link even when numerical. I'll happily volunteer to create this is people wish.

I'll generate Unit Tests for this issue as soon as I get an opportunity.

Additional failing test is @ line 465 - 494 (testCanGenerateNumericKeyUri)

Taken from trunk @ 2010-05-16 12:30pm BST

Have updated Zend_Controller_Router_Rewrite::assemble() method with alternative to array_merge() function to pass unit tests.

I've also attached an updated unit test file to perform required tests. Test is located in Zend_Controller_Router_RewriteTest::testCanGenerateNumericKeyUri().

Fixed in svn r22416 on trunk and r22417 on release-1.10. Patch by Lloyd Watkin.