I have a module named Member and have two controllers in it Member and Registration.
I need a menu which will be like "View Member" -> "Edit Member" and "Become a member" links.
The routes are as under :
'router' => array(
'routes' => array(
'member' => array(
'type' => 'segment',
'options' => array(
'route' => '/member[/:action]',
'constraints' => array(
'action' => '[a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Member\Controller\Member',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'registration' => array(
'type' => 'segment',
'options' => array(
'route' => '/registration[/:action]',
'defaults' => array(
),
),
),
),
),
'registration' => array(
'type' => 'segment',
'options' => array(
'route' => '/registration[/:action]',
'constraints' => array(
'action' => '[a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Member\Controller\Registration',
'action' => 'index',
),
),
),
),
),
The Navigation code is :
'navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'home',
'type' => 'Zend\Navigation\Page\Mvc',
),
array(
'label' => 'Member', // 'Page #1',
'route' => 'member', // 'page-1',
'action' => 'index',
'resource' => 'Member\Controller\Member',
'pages' => array(
array(
'label' => 'Edit', // 'Child #1',
'route' => 'member',
'params' => array('action' => 'memberEdit'),
'resource' => 'Member\Controller\Member',
),
),
),
array(
'label' => 'Become a member',
'route' => 'registration',
'controller' => 'registration',
'action' => 'index',
'resource' => 'Member\Controller\Registration',
),
),
),
The service manager is :
'service_manager' => array(
'factories' => array(
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
The layout code is :
$this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(1)
->setUlClass('nav navbar-nav');
All links work except the "Become a member" link. When you click on it gives an error message
Route with name "default" not found
Please help.
Change the routes -
'router' => array( 'routes' => array( 'registration' => array( 'type' => 'segment', 'options' => array( 'route' => '/registration[/:action]', 'constraints' => array( 'action' => '[a-zA-Z0-9_-]*', ), 'defaults' => array( 'controller' => 'Member\\Controller\\Registration', 'action' => 'index', ), ), ), 'member' => array( 'type' => 'segment', 'options' => array( 'route' => '/member[/:action]', 'constraints' => array( 'action' => '[a-zA-Z0-9_-]*', ), 'defaults' => array( 'controller' => 'Member\\Controller\\Member', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'registration' => array( 'type' => 'segment', 'options' => array( 'route' => '/registration[/:action]', 'defaults' => array( ), ), ),
), ), ), ),
This way you can use both registration
and member/registration
routes.
I hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.