ZF2-149: Route match does not provide matched parameters (e.g. in segment)
Description
Steps to reproduce * Create a new SkeletonApplication * Add a new route to Application module:
'test' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/test[/:id]',
'defaults' => array(
'controller' => 'index',
'action' => 'index',
'id' => 0
),
),
),
- Modify IndexController::indexAction to retrieve the parameter "id"
* echo $id and exit
* Create a new request to http:///test/1
Expected result:
The number 1 should be displayed
Actual result:
Nothing is displayed
Additional information:
It looks like Zend\Mvc\Router\SimpleRouteStack and inheritors ignore the accumulated request assembledParams in a matched Route\Segment.
Proposed solution:
Add
to Zend\Mvc\Router\SimpleRouteStack line 267 (in match() method, after the foreach loop ends) Note that this same solution may apply to Zend\Mvc\Router\TreeRouteStack for applications with a baseUrl
Comments
Posted by Christopher Valderrama (gatorv) on 2012-02-16T19:38:54.000+0000
Althought it would be a simple way to extract them, you can extract them right now if your controller implements the InjectApplicationEvent, then you can retrieve the MVC Event, and extract the route matches:
Posted by Mat Berchtold (mberchtold) on 2012-03-20T15:19:08.000+0000
The proposed solution breaks other functionality: existing params in the query are lost. The following change merges both params: $request->setQuery(new \Zend\Stdlib\Parameters(array_merge($match->getParams(), $request->query()->toArray())));
It would be great if somebody from zf could comment on this.
Posted by Ben Scholzen (dasprid) on 2012-03-20T15:29:20.000+0000
Route parameters are not query parameters, so this issue is basically invalid. What is correct is that we had Request::getParam() before, which combined all parameter sources (user params, get, post, cookie, etc.). This may return at a later point, but is not related to this issue. So right now you would do:
Posted by Mat Berchtold (mberchtold) on 2012-03-20T15:37:01.000+0000
What you probably meant is: