我是Zend Framework 2的新手,我試圖用ZF2生成動態麪包屑,但沒有成功。zend framework 2動態麪包屑 - 傳遞參數
我使用http://adam.lundrigan.ca/2012/07/quick-and-dirty-zf2-zend-navigation/作爲我的工作的基礎,並描述了我爲我的模塊公開的路由構建了站點地圖。
實施例:
// config/autoload/nav_zfcuser.global.php
<?php
return array(
// All navigation-related configuration is collected in the 'navigation' key
'navigation' => array(
// The DefaultNavigationFactory we configured in (1) uses 'default' as the sitemap key
'default' => array(
// And finally, here is where we define our page hierarchy
'home' => array(
'label' => 'Home',
'route' => 'home',
'pages' => array(
'sitemap' => array(
'label' => 'Sitemap',
'title' => 'Sitemap',
'route' => 'sitemap',
),
'aboutus' => array(...),
'privacy' => array(...),
),
),
),
),
);
然後以使麪包屑中使用的下列視圖助手:
<?php echo $this->navigation()->breadcrumbs('Navigation'); ?>
這工作正常,並且例如,如果我導航上mywebsite.com/sitemap渲染bredcrumbs將是。
首頁>網站地圖
問題是,當我開始具有動態URL's(例如用產品ID's)。
在module.config.php路由是..
<?php
return array(
'router' => array(
'routes' => array(
(...)
'productHome' => array(
'type' => "Literal",
'options' => array(
'route' => "/product",
'defaults' => array(
'__NAMESPACE__' => "Application\Controller",
'controller' => "Product",
'action' => "index",
),
),
'may_terminate' => true,
'child_routes' => array(
'product' => array(
'type' => "Segment",
'options' => array(
'route' => "/:idProduct[/:name]",
'defaults' => array(
'__NAMESPACE__' => "Application\Controller",
'controller' => "Product",
'action' => "product",
),
),
'may_terminate' => true,
),
),
上述(module.config.php)定義的路由轉換爲下列網址結構:
mysite的.com/Product /:idProduct [/名稱]
因此構建反映此結構的站點地圖應該是:
// config/autoload/nav_zfcuser.global.php
<?php
return array(
// All navigation-related configuration is collected in the 'navigation' key
'navigation' => array(
// The DefaultNavigationFactory we configured in (1) uses 'default' as the sitemap key
'default' => array(
// And finally, here is where we define our page hierarchy
'home' => array(
'label' => 'Home',
'route' => 'home',
'pages' => array(
'sitemap' => array(...),
'productHome' => array(
'label' => 'Product',
'route' => 'product',
'controller' => 'Product',
'action' => 'index',
'pages' => array(
'product' => array(
'label' => 'Product',
'controller' => 'Product',
'action' => 'product',
'route' => 'product/:idProduct[/:name]',
),
),
),
),
),
),
),
);
瀏覽器刷新頁面的產品mywebsite.com/product/flv6n768/ProductName 沒有顯示麪包屑。
如何傳遞「idProduct」和「名」 PARAMS這樣,當我打電話視圖助手
<?php echo $this->navigation()->breadcrumbs('Navigation'); ?>
它呈現:產品首頁>產品> idProduct(不可見)>的名字嗎?