我需要更改Zend_View_Helper_Navigation_Menu
的输出.我找到了需要修改的两个函数,并且知道如何进行所需的更改.我不知道如何让 Navigation 对象使用我的视图助手而不是 Zend .
I need to change the output of Zend_View_Helper_Navigation_Menu
. I've found the two functions that I'll need to modify, and I know how to make the changes I need. What I don't know is how to make the Navigation object use my view helper instead of the Zend one.
代表我的类扩展的代码片段:
Code snippet representing my class extension:
// 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
}
}
<小时>
编辑以澄清
我想更改 元素的类并删除
EOL
和缩进.菜单视图脚本没有选项可以做到这一点,这就是我必须扩展它的原因.
I want to change the class of the <li>
elements and remove the EOL
and indentation. There are no options to do that with the menu view script, which is why I'll have to extend it.
在我的 Bootstrap 中初始化导航对象:
Initializing the navigation object in my Bootstrap:
$navTable = new Default_Model_Site_DbTable_Navigation();
$view = $this->getResource('view');
$view->navigation(new Zend_Navigation($navTable->getNavigation()));
在我的布局中渲染菜单:
Rendering the menu in my layout:
echo $this->navigation()->menu();
<小时>
解决方案
我通过如下重命名使其工作,但我不清楚为什么我不能重载/覆盖 _Menu
类和 menu()
函数.
I got it working by renaming things as follows, but I am not clear on why I can't overload/overwrite the _Menu
class and menu()
function.
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
}
}
$view->addHelperPath(
APPLICATION_ROOT . '/library/MyApp/View/Helper/Navigation',
'MyApp_View_Helper_'
);
echo $this->navigation()->myMenu(); // name of your class
来自:让 Zend_Navigation 菜单工作使用 jQuery 的鱼眼
编辑
抱歉,我没有看到您的解决方案,这正是我发布的内容.
Sorry I've not seen your solution, it is exactly what I've posted.
但为什么这不是菜单类的真正扩展?
But why this is not a trully extension of menu class?
这篇关于如何扩展 Zend Navigation Menu View Helper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!