1

I am trying to remove a page from zend-navigation but it does not appear to get removed.

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() seems to correctly find the page. But removePage($page) does not remove the page. I'm doing the second findOneBy() to prove the page still exists.

How can I remove the page?

(this code is within a controller action, is that too late?)

As requested here is my config for container;

// 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'
                ),
            ),
        ),
    ),
),
srayner
  • 1,799
  • 4
  • 23
  • 39
  • Looking through the source code, it appears you can only remove root nodes. – srayner Sep 03 '16 at 11:08
  • How have you confirmed your belief that "... findOneBy() seems to correctly find the page"? Please show us your container (or enough of it to replicate your issue) so we can test your code and assumptions properly. Ref [https://zendframework.github.io/zend-navigation/containers/#removing-pages](https://zendframework.github.io/zend-navigation/containers/#removing-pages) – jwpfox Sep 03 '16 at 13:05
  • Had another look at the source code. I guess the answer is; $navigation->removePage($page, true); The docs don't mention anything about recursive delete. I should raise an issue on Github. – srayner Sep 07 '16 at 14:56

0 Answers0