0

I've already figured out how to make a simple resource reachable by AbstractRestfulController. Example:

localhost/products -> list
localhost/products/1 -> special product

Is there a way to nest resources? If so, how would you do that? Example:

localhost/products/1/photos -> list all photos of a product
localhost/products/1/photos/3124 -> show special photo of a product

(I have in this presentation as goal mind)

Thanks for your help!

FlorianX
  • 221
  • 1
  • 3
  • 7

2 Answers2

1

You need to add another route. For instance :

'products' => array(
                        'type'    => 'Literal',
                        'options' => array(
                            'route'    => '/products',
                            'defaults' => array(
                                'controller' => 'Application\Controller\ProductsRest',
                                'action'     => null
                            )
                        ),
                        'may_terminate' => true,
                        'child_routes'  => array(
                            'photos' => array(
                                'type'    => 'Segment',
                                'options' => array(
                                    'route' => '/:productId/photos'
                                )
                            ),                                
                        )
                    )
Michael Gallego
  • 1,746
  • 1
  • 20
  • 29
0
'products' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/products/:productId[/photos/:photos]',
                'constraints' => array(
                    'productId' => '[0-9]*',
                    'photos' => '[0-9]*'
                ),
                'defaults' => array(
                    'controller' => 'your contrller',
                ),
            ),
        ),
Dharmesh Vasani
  • 475
  • 2
  • 4
  • 19