> I need to retrieve my navigation in my controllers (i need breadcrumbs
> element to be in the JsonModel) for some ajax request.
> My navigation is generated by a service class that extend
> DefaultNavigationFactory. In my Layout, is no problem. I can use
> So, in my controller, i can retrieve my service like that:
> $container = $this->getServiceLocator()->get('NavigationAdmin');
> But now, how to retrieve the breadcrumbs or menu with $container ?
Those are actually two separate things -- the navigation container in
the service manager is a top-level object from the Zend\Navigation
component. The view helper "navigation" gives you access to this
container, but then provides access to additional view helpers -- that
what "breadcrumbs" and "menu" actually are, view helpers.
If you want access to those inside your controller, you will have to
inject them. You can do this by creating a factory for your
controller, and within that factory pulling the ViewHelperManager from
the service manager, and then the individual view helpers.
That said, I'd rethink _why_ you want access to the menu and
breadcrumbs in your controller. Usually, if you start mixing view
logic into controllers, it's a sign that you're mixing concerns that
Actually my goal are to output an ViewModel with the view content and the breadcrumbs, without layout (when XmlHttpRequest).
I use $view->setTerminal($this->getRequest()->isXmlHttpRequest()) to render only the view to work with pushState HTML5 when is available. And i need the breadcrumbs in this case to be include to the content. Is why i asked that question.
And when setTerminal==0 (normal request) the breadcrumbs come from the layout.
Ok i will see to inject ViewHelperManager in my controller, but can you tell me please what is the difference with that way? (i found it after i ask)
// Get View Helper Manager in action controller
$viewHelperManager = $this->getServiceLocator()->get('viewHelperManager');
// Get navigation
$navigation = $viewHelperManager->get('navigation');