Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
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.
Attachments
Issue Links
| This issue duplicates: | ||||
| ZF-7246 | Zend_Controller_Router_Rewrite should not use array_merge in assemble |
|
|
|
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.