samedi 25 avril 2015

Why is my ZF2 Segment child route being ignored?


I have the following routing config in my project:

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route' => '/',
                'defaults' => array(
                    '__NAMESPACE__' => 'MyApp\Controller',
                    'controller' => 'Default',
                    'action' => 'default',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'api' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => 'api/:action[/:id]',
                        'defaults' => array(
                            '__NAMESPACE__' => 'MyApp\Controller',
                            'controller' => 'Api',
                            'action' => 'index',
                        ),
                    ),
                    'may_terminate' => true,
                ),
                'default' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => '[:id]',
                        'defaults' => array(
                            '__NAMESPACE__' => 'MyApp\Controller',
                            'controller' => 'Default',
                            'action' => 'default',
                        ),
                    ),
                    'may_terminate' => true,
                ),
            ),
        ),
    ),
),

When I make a call to http://localhost/api/foo/bar I get the response from the DefaultController. I have stripped my application until this is the only route (removed home/default, and made it an only route for the application) but it is ignored.

The desired outcome is that calls to /api... go to the Api controller, but all other calls go to the Default Controller.

There are no errors being thrown as far as I can see (looking at apache2 logs)

Any suggestions as to what might be wrong?


Aucun commentaire:

Enregistrer un commentaire