如何将动态和静态导航与zend框架2混合使用

时间:2014-07-09 16:50:33

标签: dynamic static navigation zend-framework2

我在zend框架2中有一个项目,默认导航,与acl连接,以及来自differente模块的配置更正集(静态)。

我希望这个模块中的一个可以动态地向导航添加页面。

对于这个模块,我有module.config.ing的这一部分

'navigation' => array(
    'default' => array(
        array(
            'id' => 'page-1',
            'label' => 'Page',
            'route' => 'page',
            'resource' => 'page',
            'privilege' => 'view',
            'order' => 40
        )
     )
 )

如何以及在何处将子页面添加到该页面?

1 个答案:

答案 0 :(得分:0)

我找到了这个解决方案,我不知道这是不是最好的方法,但它确实有效。 在我的Module.php中,我把:

public function init(ModuleManager $moduleManager) {
    $events = $moduleManager->getEventManager();
    $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'));
}

public function onMergeConfig(ModuleEvent $e) {
    $pages = array(
        'id' => 'page-1',
        'label' => 'Page',
        'route' => 'page',
        'resource' => 'page',
        'privilege' => 'view',
        'order' => 40
    )

    $configListener = $e->getConfigListener();
    $config = $configListener->getMergedConfig(false);

    // Modify the configuration; here, we'll remove a specific key:
    $config['navigation']['default']['team']['pages'][] = $pages;

    // Pass the changed configuration back to the listener:
    $configListener->setMergedConfig($config);
}

现在我只需要动态加载页面。 如果有人有更完整和正确的答案,请写下来。