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

Issue Type: Bug Created: 2010-01-24T09:54:25.000+0000 Last Updated: 2010-11-29T00:47:35.000+0000 Status: Resolved Fix version(s): - 1.10.6 (22/Jun/10)

Reporter: Lloyd Watkin (lloydwatkin) Assignee: Lloyd Watkin (lloydwatkin) Tags: - Zend_Navigation

Related issues: - ZF-7246

Attachments: - ZF-8914.v2.diff


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.


Posted by Lloyd Watkin (lloydwatkin) on 2010-05-16T04:54:49.000+0000

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.

Posted by Lloyd Watkin (lloydwatkin) on 2010-05-16T05:21:38.000+0000

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

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

Posted by Lloyd Watkin (lloydwatkin) on 2010-05-16T06:56:54.000+0000

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().

Posted by Rob Allen (rob) on 2010-06-11T07:16:06.000+0000

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

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.