I'm trying to migrate my navigation from ZF1 to ZF2. I've did extract from DB, built multidimensional array, passed that to Navigation container.
I can access Navigation container from view helper, so all should be registered correctly. However, when I'm trying to generate menu in the view, I'm getting following error:
Fatal error: Zend\Navigation\Exception\DomainException: Zend\Navigation\Page\Mvc::getHref cannot execute as no Zend\Mvc\Router\RouteStackInterface instance is composed
By using URL helper manually, I can build correct URL, so route is defined OK.
Where is the problem please ? What should I check ?
UPDATE: adding code
Creating multi array:
protected function buildTree() {
$references = array();
foreach ( $this->_flatArray as &$node) {
// Add the node to our associative array using it's ID as key
$references[$node['id']] = &$node;
// Add empty placeholder for children
$node['pages'] = array();
// zvýrazníme, ak treba
if( $node['zvyraznena'] == 1 ) {
$zvyraznenie = self::_trieda_zvyraznovania;
} else {
$zvyraznenie = NULL;
}
// It it's a root node, we add it directly to the tree
if ( $node['parentId'] == self::_rootID) {
$this->_configArray[$node['id']] = &$node;
$this->_configArray[$node['id']]['class'] = $zvyraznenie;
$this->_configArray[$node['id']]['full_path'] = '';
$this->_configArray[$node['id']]['route'] = $this->_router;
$this->_configArray[$node['id']]['params'] = array('nodeID' => $node['id'], 'full_path' => $node['url'] );
} else {
// It was not a root node, add this node as a reference in the parent.
if( isset($references[$node['parentId']]['pages'][$node['id']]['class']) ) $parent_seo = $references[$node['parentId']]['pages'][$node['id']]['class'] . $parent_seo . '/';
$references[$node['parentId']]['pages'][$node['id']] = &$node;
$references[$node['parentId']]['pages'][$node['id']]['class'] = $zvyraznenie;
$references[$node['parentId']]['pages'][$node['id']]['full_path'] = $full_path = $references[$node['parentId']]['full_path'] . $node['url'] . '/';
$references[$node['parentId']]['pages'][$node['id']]['route'] = $this->_router;
$references[$node['parentId']]['pages'][$node['id']]['params'] = array('nodeID' => $node['id'], 'full_path' => rtrim($full_path, '/') );
}
}
}
Getting container:
public function buildNavigation() {
$this->buildTree();
return new \Zend\Navigation\Navigation($this->_configArray);
}
setup nav. container and helper in global.php
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
'navigation' => function() { // navigácia z DB do Service Managera
$navigation = new \Cls\Navigacia();
return $navigation->buildNavigation();
},
),
),
..and in the layout.phtml
<?php echo $this->navigation('navigation')->menu(); ?>