【问题标题】:zend_navigation and onclick attributezend_navigation 和 onclick 属性
【发布时间】:2009-08-19 18:53:17
【问题描述】:

有什么方法可以将 zend_navigation 页面类型推入 mvc 或 uri 并赋予它 onclick 属性?

array (
    'type' => 'uri', 
    'label' => 'Map', 
    'title' => 'Map', 
    'uri' => '#', 
    'click' => 'alert("show map");' )

我的子子菜单包含仅触发模式的链接。直到我使用自己的“导航”解决方案,但我想使用 zend 的解决方案。

谢谢

【问题讨论】:

    标签: php zend-framework navigation


    【解决方案1】:

    我应该提到我知道简单的解决方法 - 有一些 onload javascript 函数可以根据它们的 id 将事件附加到某些菜单,但我只想保持简单并在一个地方维护整个菜单定义。

    【讨论】:

      【解决方案2】:

      您可以编写自己的菜单助手来代替 Navigation_Menu 助手。

      主要的扩展方法是htmlify

      class MyApp_View_Helper_MyMenu extends Zend_View_Helper_Navigation_Menu
      {
      
          public function htmlify(Zend_Navigation_Page $page)
          {
              // ... put original code here ...
      
              // get attribs for element
              $attribs = array(
                  'id'     => $page->getId(),
                  'title'  => $title,
                  'class'  => $page->getClass()
              );
      
              // does page have a href?
              if ($href = $page->getHref()) {
                  $element = 'a';
                  $attribs['href'] = $href;
                  $attribs['target'] = $page->getTarget();
                  $attribs['onclick'] = $page->getClick(); // the click attribute
              } else {
                  $element = 'span';
              }
      
              return '<' . $element . $this->_htmlAttribs($attribs) . '>'
                   . $this->view->escape($label)
                   . '</' . $element . '>';
          }
      }
      

      然后,通过以下方式调用您的助手:

      <?php echo $this->navigation()->myMenu(); ?>
      

      在此处查看完整示例:Getting Zend_Navigation menu to work with jQuery's Fisheye

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-12
        • 2011-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多