如何从zend-navigation中删除页面?

时间:2016-09-03 10:55:46

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

我正在尝试从zend-navigation中删除某个页面,但它似乎没有被删除。

if (!$task->getMilestone()) {
    $navigation = $this->getServiceLocator()->get('Navigation');
    $page = $navigation->findOneBy('id', 'milestone_edit_task');
    $navigation->removePage($page);
    $page = $navigation->findOneBy('id', 'milestone_edit_task');
    die(var_dump($page->get('id')));
}

findOneBy()似乎正确找到了该页面。但是removePage($ page)不会删除页面。我正在做第二个findOneBy()来证明页面仍然存在。

如何删除页面?

(这段代码在控制器动作中,为时已晚?)

这里要求的是我的容器配置;

// Navigation
'navigation' => array(
    'default' => array(

        // Projects
        array(
            'label' => '<i class="fa fa-cubes"></i> Projects',
            'route' => 'project/default',
            'controller' => 'project',
            'pages' => array(
                array(
                    'label' => 'Project Detail',
                    'controller' => 'project',
                    'action' => 'detail',
                    'pages' => array(
                        array(
                            'label' => 'Add milestone',
                            'controller' => 'milestone',
                            'action' => 'add'
                        ),
                        array(
                            'label' => 'Edit milestone',
                            'controller' => 'milestone',
                            'action' => 'edit'
                        ),
                        array(
                            'label' => 'Delete milestone',
                            'controller' => 'milestone',
                            'action' => 'delete'
                        ),
                        array(
                            'label' => 'Add task',
                            'controller' => 'project',
                            'action' => 'task'
                        ),
                        array(
                            'label' => 'Milestone Detail',
                            'controller' => 'milestone',
                            'action' => 'detail',
                            'pages' => array(
                                array(
                                    'label' => 'Add Task',
                                    'controller' => 'task',
                                    'action' => 'add'
                                ),
                                array(
                                    'id' => 'milestone_edit_task',   // <---
                                    'label' => 'Edit Task',
                                    'controller' => 'task',
                                    'action' => 'edit'
                                ),
                                array(
                                    'label' => 'Delete Task',
                                    'controller' => 'task',
                                    'action' => 'delete'
                                ),
                                array(
                                    'label' => 'Add comment',
                                    'controller' => 'milestone',
                                    'action' => 'comment'
                                ),
                                array(
                                    'label' => 'Task Detail',
                                    'controller' => 'task',
                                    'action' => 'detail',
                                ),
                            ),
                        ),
                        array(
                            'label' => 'Add comment',
                            'controller' => 'project',
                            'action' => 'comment'
                        ),
                    ),   
                ),
                array(
                    'label' => 'Edit comment',
                    'controller' => 'comment',
                    'action' => 'edit'
                ),
                array(
                    'label' => 'Delete comment',
                    'controller' => 'comment',
                    'action' => 'delete'
                ),
            ),
        ),
    ),
),

0 个答案:

没有答案