Zend_Navigationでパンくずリストを作成

Zend_Navigationは1.8から追加された。

1.XML
pagesを入れ子にして階層構造を作れる

<?xml version=”1.0″ encoding=”UTF-8″?>
<configdata>
    <navi>
        <home>
            <label>home</label>
            <uri>/</uri>
           
            <pages>
                <list>
                    <label>layer2</label>
                    <uri>/layer/list/</uri>
                    <pages>
                        <city>
                            <label>layer3</label>
                            <uri>/sr/layer/city/</uri>
                        </city>
                    </pages>
                </list>
            </pages>
        </home>
    </navi>
</configdata>

2.action
・xmlか配列でページ情報を渡す。
$config = new Zend_Config_XML(‘アプリケーションルート/configs/navigation.xml’, ‘navi’);
$navigation = new Zend_Navigation($config);

現在のURIを取得 (/contoroller/action/)
indexactionの場合は、indexは省かれる
$uri = $this->_request->getPathInfo();

現在地をしていする(現在のURIをアクティブにする)
$this->view->navigation($navigation)->findByUri($uri)->active = true;

3.view
パンくずの表示位置に挿入する
 
<div class=”breadcrumbs”>
<?php echo $this->navigation()->breadcrumbs(); ?>
</div>

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です