On Tue, Jul 30, 2013 at 4:06 AM, MichaelB <[email protected]> wrote:
> 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
> $this->navigation()->breadcrumbs()...
>
>
> 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
shouldn't be.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to