css - Zend Framework 2 导航菜单 Twitter Bootstrap 集成

标签 css twitter-bootstrap zend-framework2

我目前正在从数据库构建菜单,代码运行良好。但是,我现在想使用 twitter bootstrap 来设计菜单样式,这就是我遇到问题的地方。有谁知道将 zend framework 2 导航菜单与 twitter bootstrap 集成的方法吗?如果有人感兴趣,生成的菜单如下所示。

<ul class="nav">
<li>
    <a href="/view-page/home">Home</a>
    <ul>
        <li>
            <a href="/view-page/coupons">Coupons</a>
            <ul>
                <li>
                    <a href="/view-page/printable-coupons">Printable Coupons</a>
                    <ul>
                        <li>
                            <a href="/view-page/cut-these-coupons">Cut these here coupons</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</li>
<li class="active">
    <a href="/view-page/about-us">About Us</a>
</li>
</ul>

最佳答案

您可以根据需要使用 partials 生成导航。

在模板中显示导航:

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

你的导航部分应该是这样的:

应用程序/导航/topnav.phtml

   <ul class="nav">
    <?php $count = 0 ?>
    <?php foreach ($this->container as $page): ?>
        <?php /* @var $page Zend\Navigation\Page\Mvc */ ?>
        <?php // when using partials we need to manually check for ACL conditions ?>
        <?php if( ! $page->isVisible() || !$this->navigation()->accept($page)) continue; ?>
        <?php $hasChildren = $page->hasPages() ?>
        <?php if( ! $hasChildren): ?>
        <li <?php if($page->isActive()) echo 'class="active"'?>>
            <a class="nav-header" href="<?php echo $page->getHref() ?>">
                <?php echo $this->translate($page->getLabel()) ?>
            </a>
        </li>
        <?php else: ?>
        <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                <span><?php echo $this->translate($page->getLabel()) ?></span>
            </a>

            <ul class="dropdown-menu" id="page_<?php echo $count ?>">
            <?php foreach($page->getPages() as $child): ?>
                <?php // when using partials we need to manually check for ACL conditions ?>
                <?php if( ! $child->isVisible() || !$this->navigation()->accept($child)) continue; ?>
                <li>
                    <a href="<?php echo $child->getHref() ?>">
                        <?php echo $this->translate($child->getLabel()) ?>
                    </a>
                </li>
            <?php endforeach ?>
            </ul>
         </li>   
        <?php endif ?>
        <?php $count++ ?>
    <?php endforeach ?>
</ul>

显然这是一个简单的示例,不会处理任意数量的导航级别,您需要添加一些额外的类名等以使其与 Bootstrap 完美配合,但您明白了。

关于css - Zend Framework 2 导航菜单 Twitter Bootstrap 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14884572/

相关文章:

html - 带有圆 Angular 边框的 div

javascript - 为 Bootstrap 模式编写回调函数

html - Bootstrap 菜单没有出现在 ipad 上

jquery - 让文本隐藏而不是堆叠在上面

php - Ajax 和下载 CSV 文件

html - 媒体查询在特定的 IE 查询中不起作用

html - 两个内联 block div 仍在垂直堆叠。 (主要内容在我的侧边栏下)HTML & CSS

html - 文本的最大高度和颜色变化

php - Zend Framework 2 SOAP 自动发现和复杂类型

mongodb - Zend Framework 2 的注释命名空间未加载 DoctrineMongoODMModule