Zend Framework

Specifying numeric parameter name for page link generates incorrect URL

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: Next Major Release
  • Fix Version/s: 1.10.6
  • Component/s: Zend_Navigation
  • Labels:
    None

Description

Tested on 1.10.0beta and 1.10.0rc1

When trying to generate links like the following:

http://localhost/news/view/6/zf-1.10.0rc1-released

Specifying the parameter '6' generates URLs as follows:

http://localhost/news/view/0/zf-1.10.0rc1-released

Casting the parameter number to a string has no effect.

Code:

$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...

http://localhost/news/view/-6-/zf-1.10.0rc1-released

...works as expected.

Issue Links

Activity

Hide
Lloyd Watkin added a comment -

The problem is the assemble() methods in Zend_Controller_Router_* classes, it is due to the way PHP's array_merge function (http://www.php.net/array_merge) 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.

Show
Lloyd Watkin added a comment - The problem is the assemble() methods in Zend_Controller_Router_* classes, it is due to the way PHP's array_merge function (http://www.php.net/array_merge) 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.
Hide
Lloyd Watkin added a comment -

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

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

Show
Lloyd Watkin added a comment - Additional failing test is @ line 465 - 494 (testCanGenerateNumericKeyUri) Taken from trunk @ 2010-05-16 12:30pm BST
Hide
Lloyd Watkin added a comment -

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

Show
Lloyd Watkin added a comment - 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().
Hide
Rob Allen added a comment -

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

Show
Rob Allen added a comment - Fixed in svn r22416 on trunk and r22417 on release-1.10. Patch by Lloyd Watkin.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: