ZF-2301: Zend_Controller_Router_Route_Regex::assemble() uses default even when parameter is matched
Description
It seems like default values are being used even when parameters are actually matched from the url. Take the following for example:
$route = new Zend_Controller_Router_Route_Regex(
"itemlist(?:/(\d+))?"
, array('page' => 1) // Defaults
, array(1 => 'page') // Parameter map
, 'itemlist/%d'
);
$values = $route->match('/itemlist/2');
var_dump($values);
$url = $route->assemble();
// Expect string(10) "itemlist/2"
var_dump($url);
$url = $route->assemble(array('page' => 2));
// Expect string(10) "itemlist/2"
var_dump($url);
Which results in:
array(1) {
["page"]=>
string(1) "2"
}
string(10) "itemlist/1"
string(10) "itemlist/2"
This appears to work fine if the parameter map is reversed so that 'page' is the key and '1' is the value.
Comments
Posted by Michal Minicki (martel) on 2008-01-11T08:17:42.000+0000
Good catch, Chris. It may be tricky to get straight, though.
As you already see, ZF supports declaring parameter names in both ways. I would like to keep it that way but I'm afraid we will have to do some magic from the looks of it.
If you already have some working code, then please go ahead and share.
Posted by Ralph Schindler (ralph) on 2008-02-28T12:07:15.000+0000
Hey Martel,
I think I've found the issue (it has to do with the way that assemble() merges data from defaults, values and provided data).
If this patch works for you, can I go ahead and commit?
Thanks, Ralph
Posted by Michal Minicki (martel) on 2008-02-28T13:22:34.000+0000
Looks very good, Ralph. Go ahead and commit. Thanks.
But for the sake of my conscience, please change the last lines of the test. This:
Should be changed into this:
First to make sure we don't get a 2 out of URL values, second to make sure parameter is being reset back to default.
Posted by Ralph Schindler (ralph) on 2008-02-29T12:58:05.000+0000
fixed in r8470
Keeping open until its merged into 1.5.0 branch.
Posted by Ralph Schindler (ralph) on 2008-02-29T13:46:35.000+0000
FIxed in both the 1.5 branch as well as trunk