I was looking for show a navigation menu in the layout.phtml file:
<?php echo $this->navigation('navigation')->menu(); ?>
So, I added these lines to /module/Application/config/module.config.php in order to declare the menu's structure according to my app routes:
'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',
),
),
),
),
),
and then I wrote a loader for the Zend/Navigation instance:
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
but I get repeatedly this exception:
Fatal error: Zend\Mvc\Router\Exception\RuntimeException: Route with name "" not found in C:\wamp\www\bsol\vendor\zendframework\zendframework\library\Zend\View\Helper\Navigation\AbstractHelper.php on line 471
I attempted to solve the problem adding this line to the menu declaration:
'pages' => array(
'route' => '/place',
'country' => array(
'label' => 'Countries',
'route' => '/place/country',
),
Nevertheless, In that case I get another different exception:
Fatal error: Uncaught exception 'Zend\Navigation\Exception\InvalidArgumentException' with message 'Invalid argument: $page must be an instance of Zend\Navigation\Page\AbstractPage or Traversable, or an array' in C:\wamp\www\bsol\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php on line 733
UPDATED: Following Jurian Sluiman's suggestion,
This must be my router configuration (module\Place\config\module.config.php), if I've got a module called 'Place', with 3 controllers (city, country and state):
'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',
),
),
),
),
),
And this must be my navigation config (actually I located this one in an autoloadable file in /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',
),
),
),
),
),
);
...And now It works!.