doupu1949 2013-10-06 01:39
浏览 42

ZF2导航:使用非默认参数激活路线?

This seems to be a similar problem but didn't work for me. I feel like the answer must be out there -- this can't be an uncommon issue -- but I'm not using the correct search terms.

ZF2: Active branch for child routes in zend navigation. How?

Here is a route I have defined:

'router' => array(
    'routes' => array(
        'platform' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/platform[/:controller/:region/:id[/:action]]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'region' => '[0-9a-z]{2,4}',
                    'id' => '[0-9a-z-]+',
                ),
                'defaults' => array(
                    'controller' => 'platform',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),

And here is my navigation:

'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
        ),
        array(
            'label' => 'Account',
            'route' => 'zfcuser',
            'pages' => array(
                array(
                    'label' => 'Dashboard',
                    'route' => 'zfcuser',
                ),
                array(
                    'label' => 'Sign In',
                    'route' => 'zfcuser/login',
                ),
                array(
                    'label' => 'Sign Out',
                    'route' => 'zfcuser/logout',
                ),
                array(
                    'label' => 'Register',
                    'route' => 'zfcuser/register',
                ),
            ),
        ),
        array(
            'label' => 'Platform v2 BETA',
            'route' => 'platform',
        ),
    ),
),

I display a top-level menu on every page in my layout like so:

                <div class="nav-collapse collapse">
                    <?php echo $this->navigation('navigation')
                                    ->menu()
                                    ->setMinDepth(0)
                                    ->setMaxDepth(0)
                                    ->setUlClass('nav')
                                    ->render(); ?>
                </div>

My navigation appears correctly and has the right section activated for home and the zfcuser routes. It is the platform route which I am having problems with. If I go to /platform the menu will be activated. However, when I browse to any other page in the module (eg. /platform/pendulum/na/af455e) there is no active menu and no breadcrumbs. The problem seems to be that the controller/action on these other pages are not the same as the default specified by the route.

How can I get any successful route match to cause the menu to activate?

  • 写回答

1条回答 默认 最新

  • douruhu4282 2014-06-05 12:50
    关注

    Put something like this in

      'invokables' => array(
            'Application\Controller\Platform'       => 'Application\Controller\PlatformController')
    

    and replace default from your above like this

     'defaults' => array(
                    'controller' => 'Application\Controller\Platform',
                    'action' => 'index',
                ),
    

    Application is Module Name In My Case

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序