2014-04-10 19 views
0

使用zf2我有一個subnav欄出現在我的一個模塊的每個頁面上。它使用視圖助手和部分視圖(全部包含在模塊中)呈現。該模塊從自己module.config.php拉配置:分離我的module.config.php中的子導航和頂級導航配置

'navigation' => array(
    'default' => array(
     array(
      'label' => 'aaa', 
      'route' => 'aaa', 
     ), 
     array(
      'label' => 'bbb', 
      'route' => 'bbb', 
     ), 
     array(
      'label' => 'ccc', 
      'route' => 'ccc', ... 

現在我想添加一個配置被應用模塊中呈現我的網站導航欄寬。當然,問題在於configs被合併,所以我不能在應用程序模塊的module.config.php中添加一個'navigation'鍵。

什麼是最好的時候處理呢?我如何讓我的模塊特定的subnavs和我的頂級導航存儲和分離在服務管理器中?

回答

0

當然,問題是,CONFIGS合併

爲什麼是一個問題?

申請(module.config.php)

'navigation' => array(
    'default' => array(
    // application pages... 
    ) 
), 

FooModule(module.config)

'navigation' = array(
    'foo_nav' => array(
    // foo pages... 
    ), 
    'foo_module_specific_sidebar_name' = array(
    // foo sidebar pages 
    ) 
), 

合併配置

'navigation' => array(
    'default' => array(
    // application pages... 
    ), 
    'foo_nav' => array(
    // foo pages... 
    ), 
    'foo_module_specific_sidebar_name' = array(
    // foo sidebar pages 
    ) 
), 

ZF2合併使用array_merge_recursive()

如果輸入數組具有相同的字符串鍵,那麼這些鍵的值將合併到一個數組中,並且這是遞歸地完成的,以便如果其中一個值本身是一個數組,則該函數將它與在另一個陣列對應的條目太

,向您提供不重複的導航名稱,並有the appropriate factories其中您將配置其實並不重要。

+0

如何訪問其他配置?現在,在這個$ this-> navbar('navigation')這樣的視圖中調用我的視圖幫助器。我將如何傳遞導航配置內的嵌套數組? – red888