2014-12-04 56 views
0

我想爲屬性頁面動態顯示頁面麪包屑。它應該是這樣的:使用ZF2動態頁面麪包屑執行

Home > Country name > City name > Property name

使用屬性ID從數據庫中檢索國家,城市和屬性的名稱。我對查詢沒有任何問題,但是如何將值傳遞給視圖?

下面是我的配置站點地圖:它只返回首頁>物業

return [ 
     'navigation' => [ 
      'default' => [ 
       'home' => [ 
       'label' => 'Home', 
       'route' => 'home-page', 
       'pages' => [ 
        'property-page' => [ 
         'label' => 'Property', 
         'module' => 'application', 
         'controller' => 'Application\Controller\Property', 
         'route' => 'property-page', 
         'action' => 'index' 
         ], 
        ], 
       ], 
       ], 
      ], 
      ]; 

回答

0

你可以做到這一點由navigationservice config。事情是這樣的:

'navigation' => function($sm) { 
       $navigation = new \Zend\Navigation\Service\DefaultNavigationFactory; 
       $navigation = $navigation->createService($sm); 

       //add here other staff for the navigation 

} 

然後,當你從數據庫中獲取的項目,你可以改變navigation就像這樣:

$navigation = $this->getServiceLocator()->get('navigation'); //get the navigation 
$page = $nav->findByLabel('country')->setLabel($country); //set country value as label 

哪裏$country是國家proprety的獲取價值。

你可以看到這個post和這個one瞭解更多詳情。

希望這會有所幫助!