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!

2 Answers 2

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'
                                )
                            ),                                
                        )
                    )
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.