2012-11-30 219 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', 
       ), 
      ), 
     ),