2012-11-30 165 views
0

我已经想通过AbstractRestfulController可以获得简单的资源。例如:Restful API Zend Framework 2

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

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

localhost/products/1/photos - >列表中选择产品的所有照片
localhost/products/1/photos/3124 - >显示产品

(我在这presentation为目标记)

感谢您的帮助的特殊照片!

回答

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