ZF2-149: Route match does not provide matched parameters (e.g. in segment)

Issue Type: Bug Created: 2012-01-24T19:31:08.000+0000 Last Updated: 2012-03-20T15:37:56.000+0000 Status: Resolved Fix version(s): Reporter: Yonni Mendes (yonman) Assignee: Ben Scholzen (dasprid) Tags: - Request

  • Routing
  • parameters

Related issues: Attachments:


Steps to reproduce * Create a new SkeletonApplication * Add a new route to Application module:

<pre class="highlight">         '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"
<pre class="highlight">
* 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:

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


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:

<pre class="highlight">
$Match = $this->getEvent()->getRouteMatch();
$Id = $Match->getParam('id', 0);

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:

<pre class="highlight">

Posted by Mat Berchtold (mberchtold) on 2012-03-20T15:37:01.000+0000

What you probably meant is:

<pre class="highlight">

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.