dev*_*erd 7 php html5 breadcrumbs view-helpers zend-framework2
我是Zend Framework2的新手,我正在寻求以下情况的建议:
我正在使用ZF2 Breadcrumbs Helper在我的项目中创建面包棒和这段代码:
//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
Run Code Online (Sandbox Code Playgroud)
渲染时看起来像这样:
主页»Lorem Ipsum1»Lorem Ipsum2»当前面包屑
探索源代码:
<div id="breadcrumbs">
<a href="/">Home</a>
»
<a href="/">Lorem Ipsum1</a>
»
<a href="/">Lorem Ipsum2</a>
» Current Crumb
</div>
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:使用Breadcrumb Helper如何获得以下源代码,以便能够按照我想要的方式设置Breadcrumbs样式?
<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>
Run Code Online (Sandbox Code Playgroud)
您可以使用视图助手设置要使用的部分:
<?php $partial = array('application/navigation/breadcrumbs.phtml', 'default') ?>
<?php $this->navigation('navigation')->breadcrumbs()->setPartial($partial) ?>
<?php echo $this->navigation('navigation')->breadcrumbs()->render() ?>
Run Code Online (Sandbox Code Playgroud)
然后你的部分将是这样的(application/navigation/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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5124 次 |
| 最近记录: |