I'm using ZfcUser module for Zend Framework 2 In Controller folder Controller
--UserController.php
--EmployerController.php
In module.config.php, I config with route
'router' => array(
'routes' => array(
'zfcuser' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/user',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'employer' => array(
'type' => 'Literal',
'options' => array(
'route' => '/employer',
'defaults' => array(
'controller' => 'ZfcUser\Controller\Employer',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'edit' => array(
'type' => 'Segment',
'options' => array(
'route' => '/edit[/:id]',
'constraints' => array(
'id' => '[0-9]+'
),
'defaults' => array(
'controller' => 'ZfcUser\Controller\Employer',
'action' => 'edit'
)
),
),
),
),
),
),
),
),
When I run link: domain.com/user/employer/edit/1
=> error: Route with name "edit" does not have child routes
=> How to fix it
I think you don't need to add the edit
as a child route in your routing configuration. If I correctly understood your case, edit
is an action
so you could just add it as an option in the employer
route juste like this :
'router' => array(
'routes' => array(
'zfcuser' => array(
'type' => 'Literal',
'options' => array(
'route' => '/user',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'employer' => array(
'type' => 'segment',
'options' => array(
'route' => '/employer/[:action[/:id]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id'=>'[0-9]+'),
'defaults' => array(
'controller' => 'ZfcUser\Controller\Employer',
'action' => 'index',
)
),
),
),
),
),
),