Question

I'm having some troubles setting up child_routes. They don't work unless I separate them, althou the end result should be the same!:

This is what I'm trying to achieve:

'router' => array(
        'routes' => array(
            'app' => array(
                'type' => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route' => '[/:info]/app',
                    'defaults' => array(
                        '__NAMESPACE__' => 'X\App',
                        'controller' => 'Index',
                        'action' => 'index',
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'example' => array(
                            'type' => 'Zend\Mvc\Router\Http\Segment',
                            'options' => array(
                                'route' => '/example[:/data]',
                                'defaults' => array(
                                    'action' => 'example',
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),

But it only works this way:

'router' => array(
        'routes' => array(
            'app' => array(
                'type' => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route' => '[/:info]/app',
                    'defaults' => array(
                        '__NAMESPACE__' => 'X\App',
                        'controller' => 'Index',
                        'action' => 'index',
                    ),                    
                ),
            ),
            'app.example' => array(
                'type' => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route' => '[/:info]/app/example[/:data]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'X\App',
                        'controller' => 'Index',
                        'action' => 'example',
                    ),
                ),
            ),
        ),

.. anyone knows what I might be doing wrong..?

Was it helpful?

Solution

Your child routes are in the wrong place, they don't belong inside the options array, nor does the may_terminate key, try this...

'router' => array(
    'routes' => array(
        'app' => array(
            'type' => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route' => '[/:info]/app',
                'defaults' => array(
                    '__NAMESPACE__' => 'X\App',
                    'controller' => 'Index',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'example' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => '/example[:/data]',
                        'defaults' => array(
                            'action' => 'example',
                        ),
                    ),
                ),
            ),
        ),
    ),
),

OTHER TIPS

You have got your syntax wrong

in the first example you have got your chil_routes definition inside your options array, it nees to be on the same level as the options array:

'router' => array(
    'routes' => array(
        'app' => array(
            'type' => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route' => '[/:info]/app',
                'defaults' => array(
                    '__NAMESPACE__' => 'X\App',
                    'controller' => 'Index',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'example' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => '/example[:/data]',
                        'defaults' => array(
                            'action' => 'example',
                        ),
                    ),
                ),
            ),
        ),
    ),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top