問題描述
我需要更改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
}
}
<小時>
編輯以澄清
我想更改 元素的類并刪除
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();
類線框:
// 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 的魚眼
編輯
抱歉,我沒有看到您的解決方案,這正是我發布的內容.
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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!