ZF2在global.php中获得另一个导航

时间:2013-07-31 18:24:05

标签: php zend-framework frameworks navigation zend-framework2

这是我在global.php中的导航

'navigation' => array(
            'default' => array(
                    'loja' => array(
                            'label' => 'Loja',
                            'route' => 'loja',
                            'params' => array('action'=>'index'),
                            'pages' => array(
                                    'estoque' => array(
                                            'label' => 'Estoque',
                                            'params' => array('action'=>'index'),
                                            'action'=>'index',
                                            'id' => 'estoque',
                                            'route' => 'estoque',
                                    )),
                    ),
               'suport'=> array(
                    'test' => array(
                            'label' => 'Loja',
                            'route' => 'loja',
                            'params' => array('action'=>'index'),
                            'pages' => array(
                                    'estoque' => array(
                                            'label' => 'Estoque',
                                            'params' => array('action'=>'index'),
                                            'action'=>'index',
                                            'id' => 'estoque',
                                            'route' => 'estoque',
                                    )),
                    ),),

当我致电导航时,默认情况下'来了,我想打电话给导航' suport',我该怎么做? 我的代码在layout.phtml ..

echo $this->navigation('Navigation')->menu()->setUlClass('nav dropdown-submenu')->renderMenu();

谢谢:)

3 个答案:

答案 0 :(得分:0)

通过扩展Zend\Navigation\Service\DefaultFactory

创建您自己的导航工厂
namespace Application\Navigation\Service;

use Zend\Navigation\Service\DefaultNavigationFactory;

class MyNavigation extends DefaultNavigationFactory
{
    public function getName() {
        return 'suport';
    }
}

并在Module.php中

public function getServiceConfig()
{
    return array(
        'invokables' => array(
            'my_navigation' => 'Application\Navigation\Service\MyNavigation'
        }
    }
}

现在您可以使用导航echo $this->navigation('my_navigation')->menu()

答案 1 :(得分:0)

首先创建一个容器:

    <?php $container = $this->navigation()->findOneByLabel('support');?>

详细了解如何在此处查找节点:http://framework.zend.com/manual/2.2/en/modules/zend.navigation.containers.html

比使用它:

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

(把它放在你的视图脚本中。)

在文档中详细了解这一点:http://framework.zend.com/manual/2.2/en/modules/zend.navigation.view.helper.menu.html

答案 2 :(得分:0)

您可以在视图脚本中尝试此操作:

像这样创建容器

<?php $container = $this->navigation('support')->getContainer(); ?>

回应容器使用这个:

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