views:

387

answers:

2

config:

resources.frontController.plugins.nav = "WD_Controller_Plugin_Nav"

bootstrap:

protected function _initAutoloader() {
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('WD_');
return $loader;
}

protected function _initNav() {
  $this->bootstrap('layout');
  $layout = $this->getResource('layout');
  $view = $layout->getView();
  $config = new Zend_Config_Xml( APPLICATION_PATH . '/configs/navigation.xml', 'nav');
  $navigation = Zend_Navigation( $config );

  $fc = Zend_Controller_Front::getInstance();
  $fc->registerPlugin( new WD_Controller_Plugin_Nav() );
  $view->navigation( $navigation );
}

library/WD/Controller/Plugin/Nav.php:

class WD_Controller_Plugin_Nav extends Zend_Controller_Plugin_Abstract {

    public function postDispatch() {
        $uri = $this->_request->getPathInfo();
            $view = Zend_Layout::getMvcInstance()->getView();
        $activeNav = $view->navigation()->findByUri($uri)->setActive(true);
    }
}

web output:

Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'FindByUri' was not found in the registry

I pretty much know what I'm doing wrong, in that I'm referencing the Zend View Helper Navigation and not the Navigation directly ( findByUri method exists in Zend_Navigation directly ), but I'm not sure how to properly reference it.

+1  A: 

Controller plugins do not have a reference to the view object by default, like Controllers do. There are plenty of different ways to grab your view instance.

One, via the ViewRenderer action helper, like so:

$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;

Two, from your layout:

$view = Zend_Layout::getMvcInstance()->getView();

Or, as always, from your application bootstrap. But that will depend on how you set it up.

Once you do that, there is a getContainer() method available to you on all Navigation view helpers. So,

$container = $view->navigation()->getContainer();

Should work for you,

jason
Ack silly me - +1 and I apologize but I already had figured this out.. I accidentally used my previous pastebin when I should have used my updated pastebin. Basically, I have a reference to view, but since I'm referencing the view helper nav and not the real nav, I can't properly invoke findByUri.. not sure how to reference the real nav object.
meder
See the revised answer!
jason
A: 

MEDER: Can you get back to me already. This is getting really ridiculous! Aim.

John