我需要更改
代表我的类扩展的代码片段:
Zend_View_Helper_Navigation_Menu
的输出。我已经找到了我需要修改的两个函数,并且知道如何进行所需更改。但我不知道如何使导航对象使用我的视图助手而不是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
}
}