ZF2导航助手getHref无法执行错误

时间:2014-05-06 22:28:14

标签: navigation zend-framework2

我正在尝试将导航从ZF1迁移到ZF2。我从DB中提取,构建了多维数组,并将其传递给Navigation容器。

我可以从视图助手访问导航容器,因此所有都应该正确注册。但是,当我尝试在视图中生成菜单时,我收到以下错误:

Fatal error: Zend\Navigation\Exception\DomainException: Zend\Navigation\Page\Mvc::getHref cannot execute as no Zend\Mvc\Router\RouteStackInterface instance is composed

通过手动使用URL帮助程序,我可以构建正确的URL,因此路由定义正常。

请问哪里有问题?我该怎么检查?

更新:添加代码

创建多数组:

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, '/') );
                }

            }

        }

获取容器:

public function buildNavigation() {

            $this->buildTree();
            return new \Zend\Navigation\Navigation($this->_configArray);
        }

设置导航。 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();
            }, 
        ),
    ),

..并在layout.phtml中

<?php echo $this->navigation('navigation')->menu(); ?>

0 个答案:

没有答案