php - ZF2 Restful hierarchical routes -


i'm trying use hierarchical resource in zf2 restful api. resource should looks clients/1/addresses. i've tried this

'clients' => array(     'type' => 'segment',     'options' => array(         'route' => '/clients[/:id]',         'constraints' => array(             'id'     => '[0-9]+',          ),          'defaults' => array(              'controller' => 'api\controller\clientcontroller',          ),      ),      'may_terminate' => true,      'child_routes' => array(          'addresses' => array(              'type'    => 'segment',              'options' => array(                  'route'    => '/addresses[/:address_id]',                  'constraints' => array(                      'address_id'     => '[0-9]+',                  ),                  'defaults' => array(                       'controller' => 'api\controller\addresscontroller',                   ),               ),           ),       ),   ), 

there conflict of both id's, don't know if rename route identifier id of resource addresses did solve it. anyway, real problem route clients/1/addresses calls get method of addresscontroller, not getlist, , think that's because zend understands id of client belongs addresses, calls method.

do know how deal this?

you right get called instead of getlist because of id being present in route match parameters , the controller default uses 'id' matching route identifier.

the way deal give route identifiers names fit resource. client make client_id , address use address_id (like did).

and configure abstractrestfulcontroller instance "look" correct route identifier using setidentifiername method:

$clientcontroller->setidentifiername( 'client_id' );  $addresscontroller->setidentifiername( 'address_id' ); 

this example, best way (of course) using controller factory...


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -