layout.phtmlファイルでナビゲーションメニューを表示することを探していました。
<?php echo $this->navigation('navigation')->menu(); ?>
そこで、アプリのルートに従ってメニューの構造を宣言するために、これらの行を/module/Application/config/module.config.phpに追加しました。
'navigation' => array(
'default' => array(
'place' => array(
'label' => 'Places',
'route' => '/place',
'pages' => array(
'country' => array(
'label' => 'Countries',
'route' => '/place/country',
),
'state' => array(
'label' => 'States',
'route' => '/place/state',
),
'city' => array(
'label' => 'Cities',
'route' => '/place/city',
),
),
),
),
),
次に、Zend/Navigationインスタンスのローダーを作成しました。
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
しかし、私はこの例外を繰り返し受けます:
致命的なエラー:Zend \ Mvc \ Router \ Exception \ RuntimeException:C:\ wamp \ www \ bsol \ vendor \ zendframework \ zendframework \ library \ Zend \ View \ Helper \ Navigation \AbstractHelper.phponに名前""のルートが見つかりません471行目
この行をメニュー宣言に追加する際の問題を解決しようとしました。
'pages' => array(
'route' => '/place',
'country' => array(
'label' => 'Countries',
'route' => '/place/country',
),
それにもかかわらず、その場合、私は別の異なる例外を受け取ります:
致命的なエラー:キャッチされない例外'Zend \ Navigation \ Exception \ InvalidArgumentException'とメッセージ'無効な引数:$pageはZend\Navigation \ Page \ AbstractPageまたはTraversableのインスタンス、またはC:\ wamp \ www\bsolの配列'である必要があります733行目の\vendor\ zendframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php
更新:Jurian Sluimanの提案に従い、
3つのコントローラー(都市、国、州)を備えた「Place」というモジュールがある場合、これは私のルーター構成(module \ Place \ config \ module.config.php)である必要があります。
'router' => array(
'routes' => array(
'city' => array(
'type' => 'segment',
'options' => array(
'route' => '/city[/:action][/:oid]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Place\Controller\City',
'action' => 'index',
),
),
),
'country' => array(
'type' => 'segment',
'options' => array(
'route' => '/country[/:action][/:oid]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Place\Controller\Country',
'action' => 'index',
),
),
),
'state' => array(
'type' => 'segment',
'options' => array(
'route' => '/state[/:action][/:oid]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Place\Controller\State',
'action' => 'index',
),
),
),
),
),
そして、これは私のナビゲーション構成である必要があります(実際には、これを/config/autoload/menu.global.phpの自動ロード可能なファイルに配置しました)。
return array(
'navigation' => array(
'default' => array(
'place' => array(
'label' => 'Places',
'route' => 'country',
'pages' => array(
'country' => array(
'label' => 'Countries',
'route' => 'country',
),
'state' => array(
'label' => 'States',
'route' => 'state',
),
'city' => array(
'label' => 'Cities',
'route' => 'city',
),
),
),
),
),
);
...そして今それは動作します!。