Zend框架:将BreadCrumbs与部分内容一起使用 [英] Zend framework: using BreadCrumbs with partial
本文介绍了Zend框架:将BreadCrumbs与部分内容一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在制作自定义面包屑时遇到了一些麻烦:
我的layout.phtml我有:
I have some trouble making a customized breadcrumb: I my layout.phtml I have:
$container = new Zend_Navigation();
$this->navigation($container);
$container->addPage(
array(
'label' => 'Dashboard',
'module' => 'default',
'controller' => 'dashboard',
'action' => 'index',
'pages' =>
array(
array(
'label' => 'Create Order',
'module' => 'default',
'controller' => 'createorder',
'action' => 'index'
),
array(
'label' => 'Query',
'module' => 'default',
'controller' => 'query',
'action' => 'index',
'pages' => array(
array(
'label' => 'View Order',
'module' => 'default',
'controller' => 'order',
'action' => 'vieworder'
)
)
),
array(
'label' => 'Administration',
'module' => 'default',
'controller' => 'admin',
'action' => 'index',
'pages' =>
array(
array(
'label' => 'News and Announcements',
'module' => 'default',
'controller' => 'admin',
'action' => 'addnews',
'pages' => array(
array(
'label' => 'Edit News and Announcements',
'module' => 'default',
'controller' => 'admin',
'action' => 'editnews'
)
)
)
)
)
)
)
);
下一行是:
echo $this->navigation()->breadcrumbs()->setPartial(array('BreadCrumb.phtml','default'));
BreadCrumb.phtml很好,但我不知道如何制作ul-li我的BreadCrumb.phtml中的菜单。如何获得我实际所在的导航?
预先感谢您的帮助。 Andrea
The BreadCrumb.phtml is called well, but I don't know how to make an ul-li menu in my BreadCrumb.phtml. How do I get the navigation I'm actually in? Thanks in advance for any help. Andrea
推荐答案
为此,您的BreadCrumb.phtml应该如下所示:
To do so, your BreadCrumb.phtml should look like this:
<?php
if (null === $this->container) {
$this->container = $this->breadcrumbs()->getContainer();
}
// find deepest active
if (!$active = $this->breadcrumbs()->findActive($this->container)) {
return '';
}
$active = $active['page'];
// put the deepest active page last in breadcrumbs
if ($this->breadcrumbs()->getLinkLast()) {
$html = ' <li>' . $this->breadcrumbs()->htmlify($active) . '</li>' . PHP_EOL;
} else {
$html = $active->getLabel();
if ($this->breadcrumbs()->getUseTranslator() && $t = $this->breadcrumbs()->getTranslator()) {
$html = $t->translate($html);
}
$html = ' <li>' . $this->escape($html) . '</li>' . PHP_EOL;
}
// walk back to root
while (($parent = $active->getParent()) != null) {
if ($parent instanceof Zend_Navigation_Page) {
// prepend crumb to html
$html = ' <li>' . $this->breadcrumbs()->htmlify($parent) . '</li>' . PHP_EOL . $html;
}
if ($parent === $this->container) {
// at the root of the given container
break;
}
$active = $parent;
}
echo strlen($html) ? $this->breadcrumbs()->getIndent() . '<ul id="breadcrumbs">' . PHP_EOL
. $html . '</ul>' . PHP_EOL : '';
?>
然后,您将得到类似的内容:
Then you will get something like this:
<ul id="breadcrumbs">
<li><a href="/home">Home</a></li>
<li><a href="/articles">Articles</a></li>
<li><a href="/shop">Shop</a></li>
<li>Last link</li>
</ul>
这篇关于Zend框架:将BreadCrumbs与部分内容一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文