我正在一个带有“普通”菜单和子菜单的网站上工作。
这是引导程序中适用于导航的方法:
引导程序.php
protected function _initNavigation()
{
$view = $this->getResource('view');
$view->addHelperPath(APPLICATION_ROOT . '/library/Pcw/View/Helper/Navigation', 'Pcw_View_Helper_');
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
$menuPartial = array('menu.phtml', 'default');
$view->navigation()->menu()->setPartial($menuPartial);
$subMenuPartial = array('submenu.phtml', 'default');
$view->navigation()->subMenu()->setPartial($subMenuPartial);
}
library/Pcw/View/Helper/Navigation/SubMenu.php
class Pcw_View_Helper_Navigation_SubMenu extends Zend_View_Helper_Navigation_Menu
{
public function subMenu(Zend_Navigation_Container $container = null)
{
return parent::menu($container);
}
}
根据 Stackoverflow 上的文档和主题,这种结构应该可以工作,但是会出现以下错误:
Fatal error: Uncaught exception 'Zend_Navigation_Exception' with message 'Bad method call: Unknown method Zend_Navigation::subMenu' in /home/prj/domains/prjon.nl/library/Zend/Navigation/Container.php:366
Stack trace:
#0 [internal function]: Zend_Navigation_Container->__call('subMenu', Array)
#1 [internal function]: Zend_Navigation->subMenu()
#2 /home/prj/domains/prjon.nl/library/Zend/View/Helper/Navigation/HelperAbstract.php(503): call_user_func_array(Array, Array)
#3 /home/prj/domains/prjon.nl/library/Zend/View/Helper/Navigation.php(132): Zend_View_Helper_Navigation_HelperAbstract->__call('subMenu', Array)
#4 /home/prj/domains/prjon.nl/Application/Bootstrap.php(410): Zend_View_Helper_Navigation->__call('subMenu', Array)
#5 /home/prj/domains/prjon.nl/Application/Bootstrap.php(410): Zend_View_Helper_Navigation->subMenu()
#6 /home/prj/domains/prjon.nl/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initNavigation() in /home/prj/domains/prjon.nl/library/Zend/Navigation/Container.php on line 366
错误很明显:找不到和调用方法 subMenu,但我创建了负责处理子菜单的助手。
有谁知道我做错了什么?
提前致谢!