问题
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