phprouteszend-framework2zend-routezend-framework-routing

Child, segment route with child route by method not routing


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',
                                    ),
                                ),
                            ),
                        )
                    ),
                ),

Solution

  • 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'
                                )
                            )
                        )
                    )
                ),