配置:
resources.frontController.plugins.nav = "WD_Controller_Plugin_Nav"
引导程序:
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 );
}
库/WD/控制器/插件/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);
}
}
网页输出:
在注册表中未找到带有消息“按名称“FindByUri”的插件的未捕获异常“Zend_Loader_PluginLoader_Exception”
我几乎知道我做错了什么,因为我引用的是 Zend View Helper Navigation 而不是直接的 Navigation ( findByUri 方法直接存在于 Zend_Navigation 中),但我不确定如何正确引用它。