2015-07-28 107 views
0

我阅读官方文档,但我不知道如何创建面包屑。这是我在module.config:面包屑。 ZF2

'gallery' => array(
      'type' => 'Segment', 
      'options' => array(
       'route' => '/gallery[/:id]', 
       'constraints' => array(
        'id' => '[0-9]+', 
       ), 
       'defaults' => array(
        '__NAMESPACE__' => 'Home\Controller', 
        'controller' => 'Gallery', 
        'action' => 'index', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'item' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/item[/:id]', 
         'constraints' => array(
          'id' => '[0-9]+', 
         ), 
         'defaults' => array(
          '__NAMESPACE__' => 'Home\Controller', 
          'controller' => 'Gallery', 
          'action' => 'item', 
         ), 
        ), 
       ), 
      ), 
     ), 
'navigation' => array(
    'default' => array(
     array(
      'label' => 'Gallery', 
      'route' => 'gallery', 
      'pages' => array(
       array(
        'label' => 'Gallery1', 
        'route' => 'gallery/1/item/', 
        'action' => 'index', 
       ), 
       array(
        'label' => 'Web', 
        'route' => 'gallery/2/item/', 
        'action' => 'index', 
       ), 
      ), 
     ), 
    ), 
), 

这item.php:

$this->navigation('navigation') 
      ->breadcrumbs() 
      ->setMinDepth(0) 
      ->setPartial('partial/breadcrumb.phtml'); 

而这breadcrumb.phtml:

<ul class="breadcrumb"> 
<?php 

foreach ($this->pages as $key => $page): 
    ?> 
    <li> 
     <?php 
     if ($key < count($this->pages) - 1): 
      ?> 
      <a href="<?php echo $page->getHref(); ?>"><?php echo $page->getLabel(); ?></a> 
      <?php 

     else: 
      ?> 
      <?php echo $page->getLabel(); ?> 
     <?php endif; ?> 
    </li> 
<?php endforeach; ?> 

这不是加工。有谁知道如何解决它?

+0

''route'=>'gallery/item''必须是路由名称不是路由路径 – newage

回答

0

您的配置无效。其他会好的。

'router' => array(
    'routes' => array(
     'gallery' => array(
      'type' => 'Segment', 
       'options' => array(
        'route' => '/gallery[/:gallery_id][/]', /* Gallery id */ 
        'constraints' => array(
         'gallery_id' => '[0-9]+', 
        ), 
        'defaults' => array(
         '__NAMESPACE__' => 'Home\Controller', 
         'controller' => 'Gallery', 
         'action' => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'item' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => 'item[/:item_id][/]', /* Item id */ 
          'constraints' => array(
           'item_id' => '[0-9]+', 
          ), 
          'defaults' => array(
           '__NAMESPACE__' => 'Home\Controller', 
           'controller' => 'Gallery', 
           'action' => 'item', 
          ) 
         ) 
        ) 
       ) 
      ) 
     ) 
    ) 
), 
'navigation' => array(
    'default' => array(
     array(
      'label' => 'Gallery', 
      'route' => 'gallery', 
      'pages' => array(
       array(
        'label' => 'Gallery1', 
        'route' => 'gallery/item', /* Route name */ 
        'action' => 'index', 
        'params' => array(/* Route parameters */ 
         'gallery_id' => '1', 
        ), 
       ), 
       array(
        'label' => 'Web', 
        'route' => 'gallery/item', 
        'action' => 'index', 
        'params' => array(
         'gallery_id' => '2', 
        ) 
       ) 
      ) 
     ) 
    ) 
)