0

我已经想出了如何使一个简单的资源可以通过AbstractRestfulController. 例子:

localhost/products-> 列表
localhost/products/1-> 特殊产品

有没有办法嵌套资源?如果是这样,你会怎么做?例子:

localhost/products/1/photos-> 列出产品的所有照片
localhost/products/1/photos/3124-> 显示产品的特殊照片

(我在这个演示文稿中作为目标头脑)

谢谢你的帮助!

4

2 回答 2

1

您需要添加另一条路线。例如 :

'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'
                                )
                            ),                                
                        )
                    )
于 2012-12-04T20:50:34.363 回答
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',
                ),
            ),
        ),
于 2015-07-22T13:59:40.067 回答