我需要更改Zend_View_Helper_Navigation_Menu
. 我找到了需要修改的两个函数,并且我知道如何进行所需的更改。我不知道如何让 Navigation 对象使用我的视图助手而不是 Zend 。
代表我的类扩展的代码片段:
// file /library/My/View/Helper/Navigation/Menu.php
class My_View_Helper_Navigation_Menu extends Zend_View_Helper_Navigation_Menu
{
protected function _renderDeepestMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth)
{
// modified code here
}
protected function _renderMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth,
$onlyActive)
{
// modified code here
}
}
澄清的编辑
我想更改<li>
元素的类并删除EOL
和缩进。菜单视图脚本没有选项可以做到这一点,这就是我必须扩展它的原因。
在我的 Bootstrap 中初始化导航对象:
$navTable = new Default_Model_Site_DbTable_Navigation();
$view = $this->getResource('view');
$view->navigation(new Zend_Navigation($navTable->getNavigation()));
在我的布局中渲染菜单:
echo $this->navigation()->menu();
解决方案
我通过如下重命名它来工作,但我不清楚为什么我不能重载/覆盖_Menu
类和menu()
函数。
- 将类名更改为
My_View_Helper_Navigation_MyMenu
- 将
myMenu
函数添加到类 (return parent::menu($container);
) - 调用
echo $this->navigation()->myMenu();
布局
类线框:
// file /library/My/View/Helper/Navigation/MyMenu.php
class My_View_Helper_Navigation_MyMenu extends Zend_View_Helper_Navigation_Menu
{
public function myMenu(Zend_Navigation_Container $container = null)
{
return parent::menu($container);
}
protected function _renderDeepestMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth)
{
// modified code here
}
protected function _renderMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth,
$onlyActive)
{
// modified code here
}
}