Zend Framework 2 Part Route Assembly

My Zend Framework 2 application has a route definition that tries to mimic the default Zend Framework 1 route. It looks like this:

'router' => array( 'routes' => array( 'default' => array( 'type' => 'segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'defaults' => array( '__NAMESPACE__' => 'Application\Controller', 'controller' => 'Index', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'wildcard' => array( 'type' => 'wildcard', ), ), ), ), ), 

It exactly matches the routes, but I cannot collect routes with arbitrary parameters using the Url helper helper.

For example,

 $this->url('default', array('controller' => 'test', 'action' => 'test', 'id' => 5)); 

leads to /test/test instead of /test/test/id/5 .

Does anyone know how to collect partial routes like this? Or is there a better way to get ZF1 style routes?

+7
source share
1 answer

Turns out you need to specify the name of the entire route (including child routes) in the Url view assistant.

Using the router defined in my question, the correct view assistant call will look like this:

 $this->url('default/wildcard', array('controller' => 'test', 'action' => 'test', 'id' => 5)); 

which will result in the url /test/test/id/5 .

+10
source

All Articles