0

The top router here works. /property is a Literal route that doesn't terminate and picks up on GET actions on the child route. Below that I have a segment route that, like its parent, doesn't terminate and picks up on GET actions on the child route. It should respond to GET requests only on /property/12

I get a not-found error when routing there.

'router' => array(
    'routes' => array(
        'property' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/property',
            ),
            'may_terminate' => false,
            'child_routes' => array(
                'get' => array(
                    'type' => 'method',
                    'options' => array(
                        'verb' => 'GET',
                        'defaults' => array(
                            'controller' => 'Property\Controller\Rest',
                            'action' => 'get',
                        ),
                    ),
                ),
                'by_id' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/[:propertyId]',
                        'may_terminate' => false,
                        'child_routes' => array(
                            'get_by_id' => array(
                                'type' => 'method',
                                'options' => array(
                                    'verb' => 'GET',
                                    'defaults' => array(
                                        'controller' => 'Property\Controller\Rest',
                                        'action' => 'getById',
                                    ),
                                ),
                            ),
                        )
                    ),
                ),
Wilt
  • 41,477
  • 12
  • 152
  • 203
Bluebaron
  • 2,289
  • 2
  • 27
  • 37

1 Answers1

2

Your array is invalid. 'may_terminate' is not supposed to be inside 'options'. Not sure if this is causing all your issues, but try to update and see if it is solved:

            'by_id' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/[:propertyId]'
                ),
                'may_terminate' => false,
                'child_routes' => array(
                    'get_by_id' => array(
                        'type' => 'method',
                        'options' => array(
                            'verb' => 'GET',
                            'defaults' => array(
                                'controller' => 'Property\Controller\Rest',
                                'action' => 'getById'
                            )
                        )
                    )
                )
            ),
Wilt
  • 41,477
  • 12
  • 152
  • 203
  • Perfect. Yeah I feel duh now. – Bluebaron Jul 28 '15 at 19:57
  • @Bluebaron Don't worry, you're not the only one making this mistake. Check the **Warning** at the bottom of [the official ZF2 documentation for Routing](http://framework.zend.com/manual/current/en/modules/zend.mvc.routing.html) – Wilt Jul 29 '15 at 07:37