ZF2导航问题

时间:2014-06-04 08:15:42

标签: php zend-framework2

我有一个名为Member的模块,其中有两个控制器成员和注册。

我需要一个类似“查看会员”的菜单 - > “编辑会员”和“成为会员”链接。

路线如下:

'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',
                ),
            ),
        ),
    ),
),

导航代码为:

'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',
        ),
    ),
),

服务经理是:

    'service_manager' => array(
    'factories' => array(
        'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
    ),
),

布局代码是:

$this->navigation('navigation')
                                ->menu()
                                ->setMinDepth(0)
                                ->setMaxDepth(1)
                                ->setUlClass('nav navbar-nav');

除“成为会员”链接外,所有链接均有效。当您单击它时会显示错误消息

Route with name "default" not found

请帮忙。

1 个答案:

答案 0 :(得分:0)

更改路线 -

'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( ), ), ),
), ), ), ),

这样您就可以使用registrationmember/registration路由。

我希望它有所帮助。

相关问题