Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2 Part Route Assembly

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

        '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 matches routes just fine, but I can't assemble routes with arbitrary parameters using the Url view helper.

For example,

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

results in /test/test instead of /test/test/id/5.

Does anyone know how to assemble partial routes like this? Or is there a better way of getting ZF1-style routes?

like image 687
Blake Avatar asked Aug 13 '12 00:08

Blake


1 Answers

It turns out that you need to specify the entire route name (including child routes) in the Url view helper.

Using the router defined in my question, the proper view helper call would look like:

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

which would result in a url of /test/test/id/5.

like image 106
Blake Avatar answered Sep 22 '22 02:09

Blake