Using ZF3, I'd like to access URLs like :
/dossier/add
/dossier/edit/2
/dossier/edit/2/droit/add
/dossier/edit/2/droit/edit/3
...
Here is my routing config :
'dossier' => [
'type' => Segment::class,
'options' => [
'route' => '/dossier[/][:action][/:dosid]',
'constraints' => [
'action' => '[a-zA-Z0-9_-]+',
'dosid' => '[0-9_-]*|b[0-9]+|all'
],
'defaults' => [
'controller' => Controller\DossierController::class,
'action' => 'add',
],
],
'may_terminate' => true,
'child_routes' => [
'droit' => [
'type' => Segment::class,
'options' => [
'route' => '/droit[/][:action][/:droid]',
'constraints' => [
'action' => '[a-zA-Z0-9_-]+',
'droid' => '[0-9_-]*|b[0-9]+|all'
],
'defaults' => [
'controller' => Controller\DroitController::class,
'action' => 'add',
],
]
]
]
]
Both parent and child routes possess an "action" param. This config is working fine when called directly (i.e. entering url "/dossier/edit/3/droit/delete/2" in browser). However, building the URL using viewHelper Url :
$this->url('dossier/droit', ['action' => 'delete', 'dosid' => 3, 'droid' => 2]);
produces URL :
/dossier/delete/3/droit//2
while displaying the creation ("add") view, instead of URL :
/dossier/edit/3/droit/delete/2
From topic Zf2 view helper URL child route with same params, I know I can create one child route per child action, hence getting rid of the second "action" param, but this doesn't seem quite right.
I can't help but wonder why would I be able to have both parent and child route of type Segment and still being stuck because there is no way to rename the "action" param without breaking ZF's way of routing URLs to controller methods.
Route "droit" has to be a child route of "dossier" since it needs the id of the dossier (and putting the dossier's id in a hidden input in the form seems like an even worse solution).
Am I missing something? Isn't there any better solution?