の出力を変更する必要がありますZend_View_Helper_Navigation_Menu
。変更する必要がある 2 つの関数を見つけ、必要な変更を行う方法を知っています。私が知らないのは、Navigation オブジェクトが Zend の代わりにビュー ヘルパーを使用するようにする方法です。
クラス拡張を表すコード スニペット:
// 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
、インデントを削除したいと考えています。メニュー ビュー スクリプトでそれを行うオプションはありません。そのため、これを拡張する必要があります。
Bootstrap でナビゲーション オブジェクトを初期化する:
$navTable = new Default_Model_Site_DbTable_Navigation();
$view = $this->getResource('view');
$view->navigation(new Zend_Navigation($navTable->getNavigation()));
私のレイアウトでメニューをレンダリングする:
echo $this->navigation()->menu();
解決
_Menu
次のように名前を変更して機能させましたが、クラスとmenu()
関数をオーバーロード/上書きできない理由がわかりません。
- クラス名を次のように変更します
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
}
}