2010-09-08 59 views
2

嘿,我已經得到了Zend導航在navigation.xml是這樣的:Zend框架動態麪包拉布勒

<nav> 
    <home> 
     <label>Home</label> 
     <controller>index</controller> 
     <resource>index</resource> 
     <action>index</action> 
     <pages> 
      <Reports> 
       <label>Reports</label> 
        <controller>Reports</controller> 
        <resource>Reports</resource> 
        <action>index</action> 
      </Reports> 
     </pages> 
    </home> 
</nav> 

,我已經通過

$this->navigation()->breadcrumbs() 

這工作正常初始化我的麪包屑只要頁面在navigation.xml中,但我想要的是,例如有一個名爲「今日報告」的報告,那麼麪包屑應該看起來像:Home> Reports> Today's Report,換句話說動態麪包屑,有沒有辦法做到這一點?還是應該實施我自己的?我應該拋棄XML並且應該使用數組進行導航,然後這些導航都是從數據庫動態構建的,然後將該對象存儲到註冊表中?但是我不想讓所有這些都出現在導航中,它應該只適用於麪包屑。有什麼想法嗎?

回答

2

你需要你的XML更改爲以下:

<nav> 
    <home> 
     <label>Home</label> 
     <controller>index</controller> 
     <resource>index</resource> 
     <action>index</action> 
     <pages> 
      <Reports> 
       <label>Reports</label> 
       <controller>Reports</controller> 
       <resource>Reports</resource> 
       <action>index</action> 
       <pages> 
        <TodayReport> 
         <label>Today Report</label> 
         <controller>Reports</controller> 
         <action>today-report</action> 
              <visible>0</visible> 
        </TodayReport> 
       </pages> 
      </Reports> 
     </pages> 
    </home> </nav> 

今天報告會由於被隱藏(0),但爲麪包屑使用下面使他們: $這個 - >導航() - >麪包屑() - > setRenderInvisible(TRUE);

您可以從數據庫生成一個導航對象,這不是在文檔中自己解釋的,但您可以瞭解如何創建導航對象。 http://framework.zend.com/manual/en/zend.navigation.pages.html

+0

太棒了!這是我遇到的確切問題。我想隱藏主導航欄中的選項,讓頁面出現在我的站點地圖中,但也在頁面上包含麪包屑(直到現在才隱藏)。謝謝! – scottystang 2012-08-31 20:49:12

0

如果只是麪包屑,而不是地圖,不會使最後一個元素,並使用標題,你可能已經顯示在頁面上:

<?= $this->navigation()->breadcrumbs()->setMinDepth(0) . ' > ' . $this->title ?> 

否則,您必須遍歷容器並進行手動更換。