1

現在、ZF2 で Zend Navigation を使用していますが、次の問題に遭遇しました。

私のアプリケーションモジュールには、次の設定があります(デフォルトのスケルトンアプリ)

....
'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),
        // The following is a route to simplify getting started creating
        // new controllers and actions without needing to create a new
        // module. Simply drop new controllers in, and you can access them
        // using the path /application/:controller/:action
        'application' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/application',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
        'info' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/phpinfo',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'info',
                ),
            ),
        ),
    ),
),
....
'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
            'order' => -1,
            'pages' => array(
                array( //<-- this isn't working gives a link to /application
                    'label'         => 'Telefoonboek',
                    'route'         => 'application',
                    'module'        => 'application',
                    'controller'    => 'telefoonboek',
                    'action'        => 'index',
                ),
                array( //<-- this works
                    'label'         => 'Telefoonboek2',
                    'uri'           => '/application/telefoonboek', 
                ),
                array( //<-- this works
                    'label'         => 'info',
                    'route'         => 'info',
                ),
            ),
        ),

    ),
),
....

現在、メニューに必要な「すべての」アイテムのルートを追加した場合にのみ、ナビゲーションを機能させることができます。しかし、これは一種の奇妙な解決策です。

それで、これはメニューを機能させる正しい方法ですか、それともページで何か特別なことをする必要がありますか?

4

1 に答える 1

2

私は実際にそれを自分で動作させました:)親(アプリケーション)ルートを使用する代わりに、子ルートアプリケーション/デフォルトの問題を解決する必要がありました

したがって、構成は次のようになります

   ....
'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
            'order' => -1,
            'pages' => array(
                array( //<-- this NOW works too
                    'label'         => 'Telefoonboek',
                    'route'         => 'application/default',
                    'controller'    => 'telefoonboek',
                    'action'        => 'index',
                ),
                array( //<-- this works
                    'label'         => 'Telefoonboek2',
                    'uri'           => '/application/telefoonboek', 
                ),
                array( //<-- this works
                    'label'         => 'info',
                    'route'         => 'info',
                ),
            ),
        ),

    ),
),
....
于 2013-03-21T10:29:07.210 に答える