【发布时间】:2011-01-22 19:25:52
【问题描述】:
我需要更改Zend_View_Helper_Navigation_Menu 的输出。我找到了需要修改的两个函数,并且我知道如何进行所需的更改。我不知道的是如何让 Navigation 对象使用我的视图助手而不是 Zend 。
代表我的类扩展的代码 sn-p:
// 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
}
}
【问题讨论】:
标签: php zend-framework zend-view zend-navigation