zend_navigation and onclick attribute

风流意气都作罢 提交于 2019-12-23 04:50:48

问题


is there any way how to push into zend_navigation page type mvc or uri and give it onclick attribute?

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

i have sub sub menus included links which fires only modal. till yet i use my own "navigation" solution but i want to use zend´s one.

thank


回答1:


i should mention that i know simple workaround - have some onload javascript function which attach events to some menu according their id´s but i just want to keep it simple and maintain whole menu definition at one place.




回答2:


You can write your own menu helper instead of Navigation_Menu helper.

The main method to extend is 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 . '>';
    }
}

Then, call your helper via:

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

see full example here: Getting Zend_Navigation menu to work with jQuery's Fisheye



来源:https://stackoverflow.com/questions/1301927/zend-navigation-and-onclick-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!