2013-09-24 69 views
2

我是zend框架的新手,我基於此鏈接(http://zf2.readthedocs.org/en/latest/tutorials/tutorial.navigation.html),但麪包屑未顯示在視圖或佈局中。 以下是我實施的代碼。指導我我做錯了什麼?導航在zend框架中沒有渲染的麪包屑2

在module.config.php,

return array(
    ........ 
    'router' => array(
     'routes' => array(
      'admin' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '/admin[/][:action][/:id]', 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'  => '[0-9]+', 
        ), 
        'defaults' => array(
         'controller' => 'Admin\Controller\Admin', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'settings' => array(
         'type' => 'Segment', 
         'may_terminate' => true, 
         'options' => array(
          'route' => '/general[/][:action][/][:id]', 
          'constraints' => array(
           'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'id'  => '[0-9]+', 
          ), 
          'defaults' => array(
           'controller' => 'Admin\Controller\Settings\General', 
           'action'  => 'index', 
          ), 
         ), 
        ), 
       ), 
      ), 
      'dashboard' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '/admin/dashboard[/][:action][/:id]', 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'  => '[0-9]+', 
        ), 
        'defaults' => array(
         'controller' => 'Admin\Controller\Dashboard', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
     ), 
    ), 
    'navigation' => array(
     'default' => array(
      array(
       'label' => 'Home', 
       'route' => 'admin/dashboard', 
      ), 
      array(
       'label' => 'Admin', 
       'route' => 'admin/settings/general/', 
       'pages' => array(
        array(
         'label' => 'General', 
         'route' => 'admin/settings/general/', 
         'action' => 'index', 
        ), 
        array(
         'label' => 'Web', 
         'route' => 'admin/settings/general/', 
         'action' => 'web', 
        ), 
       ), 
      ), 
     ), 
    ), 
'view_manager' => array(
     'template_map' => array(
      'layout/sidemenu'   => __DIR__ . '/../view/admin/common/sidemenu.phtml', 
      'layout/breadcrumbs'   => __DIR__ . '/../view/admin/common/breadcrumbs.phtml', 
      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ), 
     'template_path_stack' => array(
      'admin' => __DIR__ . '/../view', 
     ), 
     'display_not_found_reason' => true, 
     'display_exceptions'  => true, 
     'not_found_template'  => 'error/404', 
     'doctype'     => 'HTML5', 
     'exception_template'  => 'error/index', 
    ), 
    'service_manager' => array(
     'factories' => array( 
      'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory', 
     ), 
    ), 
    ...... 
); 

在layout.phtml

$this->navigation('navigation') 
       ->breadcrumbs() 
       ->setMinDepth(0) 
       ->setPartial('layout/breadcrumbs'); 

回答

1

請更改路由條件 '管理/儀表板' 到 '管理/默認'。如果仍不能再在你的module.php執行下面的代碼工作,你可以趕上matchedRoute:

/* put these lines on top after namespace */ 

use Zend\Mvc\ModuleRouteListener; 

use Zend\Mvc\MvcEvent; 

/* put these functions in class */ 

public function onBootstrap(MvcEvent $e) 
{ 
    $eventManager = $e->getApplication()->getEventManager(); 
    $eventManager->attach('route', array($this, 'onRouteFinish'), -100); 
} 

public function onRouteFinish($e) 
{ 
    $matches = $e->getRouteMatch(); 
    $controller = $matches->getParam('controller'); 
    var_dump($matches);die(); 
} 

在結果,請檢查["matchedRouteName":protected]的價值,改變你的路由條件在module.config.php因此。祝你好運..!!