如何扩展Zend Navigation Menu View Helper? [英] How do I extend the Zend Navigation Menu View Helper?
问题描述
我需要更改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
}
}
编辑以澄清
我想更改<li>
元素的类,并删除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();
- Change the class name to
My_View_Helper_Navigation_MyMenu
- Add the
myMenu
function to the the class (return parent::menu($container);
) - Call
echo $this->navigation()->myMenu();
in the layout
线框类:
// 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的Fisheye
编辑
对不起,我没有看到您的解决方案,这正是我发布的内容.
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!