2012-11-15 27 views
5

Tôi mới đến Zend Framework2 và Tôi đang xin lời khuyên cho các tình huống sau đây:ZF2 Breadcrumbs Helper - Cách hiển thị nó như một danh sách không có thứ tự?

tôi đang sử dụng các ZF2 Breadcrumbs Helper để tạo breadcrums về dự án của tôi và mã này:

//breadcrumbs.phtml 

echo $this->navigation('Navigation') 
     ->breadcrumbs() 
     ->setLinkLast(false)    // link last page 
     ->setMaxDepth(7)     // stop at level 7 
     ->setMinDepth(0)     // start at level 0 
     ->setSeparator(' »' . PHP_EOL); // separator with newline 

vẻ khi trả lại như thế này:

Trang chủ »Lorem Ipsum1» Lorem Ipsum2 »Current Crumb

Khám phá mã nguồn:

<div id="breadcrumbs"> 
    <a href="/">Home</a> 
    » 
    <a href="/">Lorem Ipsum1</a> 
    » 
    <a href="/">Lorem Ipsum2</a> 
    » Current Crumb 
</div> 

Vì vậy, câu hỏi của tôi là: sử dụng Helper Breadcrumb làm thế nào tôi có thể lấy mã nguồn sau đây để có thể tạo kiểu cho Breadcrumbs cách tôi muốn?

<div id="breadcrumbs"> 
    <ul id="breadcrumbs"> 
     <li><a href="">Home</a></li> 
     <li><a href="">Lorem Ipsum1</a></li> 
     <li><a href="">Lorem Ipsum2</a></li> 
     <li><a href="" class="current">Current Crumb</a></li> 
    </ul> 
</div> 

Trả lời

0

Tôi không chắc chắn nếu điều này sẽ giúp bạn, nhưng sự tiến bộ nên được tương tự như: Here

Thông tin thêm: zf2 documentation breadcrumbs Rendering sử dụng một kịch bản xem phần

+0

tôi đang sử dụng ZF2 Navigation Helper để tạo Breadcrumbs. Ví dụ mà bạn đã đăng liên quan đến cách Breadcrumbs được tạo bằng phiên bản ZF trước đó phải không? – devanerd

+0

liên kết stackoverflow có thể, nhưng tài liệu hướng dẫn về zf2. –

8

Bạn có thể sử dụng xem người trợ giúp để đặt một phần để sử dụng:

<?php $partial = array('application/navigation/breadcrumbs.phtml', 'default') ?> 
<?php $this->navigation('navigation')->breadcrumbs()->setPartial($partial) ?> 
<?php echo $this->navigation('navigation')->breadcrumbs()->render() ?> 

Và sau đó một phần của bạn sẽ là một cái gì đó như thế này (ứng dụng/điều hướng/breadcrumbs .phtml):

<?php $container = $this->navigation()->breadcrumbs() ?> 
<?php /* @var $container \Zend\View\Helper\Navigation\Breadcrumbs */ ?> 
<?php $navigation = $container->getContainer() ?> 
<?php /* @var $navigation \Zend\Navigation\Navigation */ ?> 

<ul class="breadcrumb"> 
    <li><a href="<?php echo $this->url('soemroute') ?>">Home</a> <span class="divider">/</span></li> 
    <?php foreach($this->pages as $page): ?> 
     <?php /* @var $page \Zend\Navigation\Page\Mvc */ ?> 
     <?php if(! $page->isActive()): ?> 
      <li> 
       <a href="<?php echo $page->getHref() ?>"><?php echo $page->getLabel() ?></a> 
       <span class="divider">/</span> 
      </li> 
     <?php else: ?> 
      <li class="active"> 
       <?php if($container->getLinkLast()): ?><a href="<?php echo $page->getHref() ?>"><?php endif ?> 
       <?php echo $page->getLabel() ?> 
       <?php if($container->getLinkLast()): ?></a><?php endif ?> 
      </li> 
     <?php endif ?> 
    <?php endforeach ?> 
</ul> 
0

tôi chỉ cần tạo một mẩu bánh mì Twitter Bootstrap trên ZF2 tôi

breadcrumb.phtml

<?php 
if (count($this->pages) > 0) : 
?> 
<ol class="breadcrumb"> 
<?php 
for ($i = 0, $iend = count($this->pages); $i < $iend; $i++) : 
    $a=$this->pages[$i]; 
    $label = $this->translate($a->getLabel()); 
?> 
    <li <?php if ($i + 1 == $iend) : ?> class="active" <?php endif ?> > 
     <?php if ($i + 1 != $iend) : ?> 
      <a href="<?php echo $a->getHref(); ?>"><?php echo $label ?></a> 
     <?php else : ?> 
      <?php echo $label ?> 
     <?php endif ?> 
    </li> 
<?php endfor ?> 
</ol> 
<?php endif ?> 

Và in trên mẫu của tôi

<?php echo $this->navigation()->breadcrumbs('Navigation')->setPartial('partial/breadcrumb.phtml'); ?> 
Các vấn đề liên quan