如何扩展Zend Navigation Menu View Helper? [英] How do I extend the Zend Navigation Menu View Helper?

查看:69
本文介绍了如何扩展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.

  1. 将类名称更改为My_View_Helper_Navigation_MyMenu
  2. myMenu函数添加到类(return parent::menu($container);)
  3. 在布局中调用echo $this->navigation()->myMenu();
  1. Change the class name to My_View_Helper_Navigation_MyMenu
  2. Add the myMenu function to the the class (return parent::menu($container);)
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆