title: ZF2 - Add pages to navigation in the controller
body: <p>In my project I have a navigation, which is created from an array in a config.php file using the default factory. I want to add subpages to the current pages in the controller. </p>
  
  <pre><code>class IndexController extends AbstractActionController {
      public function newpageAction() {
          $navigation = $this-&gt;getServiceLocator()-&gt;get('navigation');
          $currentPage = $navigation-&gt;findById('index');
  
          $options = array(
              'id'         =&gt; 'newpage',
              'label'      =&gt; 'New Page',
              'route'      =&gt; 'my-route',
              'controller' =&gt; 'index',
              'action'     =&gt; 'newpage',
              'active'     =&gt; true,
          );
          $newpage = new \Zend\Navigation\Page\Mvc($options);
  
          $currentPage-&gt;addPage($newpage);
      }
  }
  </code></pre>
  
  <p>The page is added successfully but then I try to create the url for the page in the breadcrumbs view using the getHref() method of the page:</p>
  
  <pre><code>&lt;?php foreach($this-&gt;pages as $page) {?&gt;
  &lt;li&gt;
      &lt;a href="&lt;?php echo $page-&gt;getHref();?&gt;"&gt;&lt;?php echo $page-&gt;getLabel();?&gt;&lt;/a&gt;
  &lt;/li&gt;
  &lt;?php }?&gt;
  </code></pre>
  
  <p>But I get the following error for the newly added pages:</p>
  
  <pre><code>Additional information:
  Zend\Navigation\Exception\DomainException
  
  File:
  \vendor\zendframework\zendframework\library\Zend\Navigation\Page\Mvc.php:198
  
  Message:
  
  Zend\Navigation\Page\Mvc::getHref cannot execute as no Zend\Mvc\Router\RouteStackInterface instance is composed
  </code></pre>
  
  <p>I guess the problem is in the way I create and add the pages to the navigation. Is there another way to do that or how I fix this error?</p>
  
  <p>I want to add the pages after the 3th level in the controller instead of in the config file because there are params in the urls of the pages and the labels are dynamic.
  Any suggestions for accomplishing this task in any other way are welcome. </p>