Zend 2 Navigation在标签名称前添加<i>

时间:2015-06-09 04:07:53

标签: php zend-framework2

我有以下导航阵列,但现在我想要一个我的标签。

我如何以及在何处添加此内容?

输出必须是:

<ul class="sidebar-nav">
    <li class="active">
        <a href="/admin/users"><i class="gi gi-user sidebar-nav-icon"></i> Users</a>
    </li>
</ul>

阵列模块配置:

 'navigation' => array(
     'default' => array(
         array(
             'label' => 'Users',
             'route' => 'user_list',
             'pages' => array(
                 array(
                    'label' => 'add user',
                    'route' => 'user_add',
                 ),
             ),
         ),

导航:

echo $this->navigation('navigation')
    ->setTranslator($this->plugin('translate')->getTranslator())
    ->menu()
    ->setUlClass('sidebar-nav')
    ->setMaxDepth(0)

1 个答案:

答案 0 :(得分:1)

您必须为Zend_Navigation设置新模板

在数组中添加图标信息

'navigation' => array(
     'default' => array(
         array(
             'label' => 'Users',
             'icon'  => 'gi gi-user',
             'route' => 'user_list',
             'pages' => array(
                 array(
                    'label' => 'add user',
                    'route' => 'user_add',
                 ),
             ),
         ),

创建一个新的topnav.phtml模板,这是我在之前项目中使用的模板。小心 !有很多不同之处,因为我使用了其他一些选项。它只是一个样本。

    <ul class="nav navbar-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): ?>
            <?php
                $class="";
                $class.=$page->isActive(true)?' active ':'';
                $class.=$page->get('class')?$page->get('class'):'';
            ?>
        <li <?php if($class) echo 'class="'.$this->escapehtmlattr($class).'"';?>>
            <a class="nav-header" href="<?php echo $page->getHref() ?>" <?php if ($page->getTitle()) echo 'title="'.$this->escapehtmlattr($page->getTitle()).'"'; ?>>
                <?php if ($page->get('icon')):?>
                <i class="<?php echo $page->get('icon');?>"></i>
                <?php endif;?>
                <?php echo $this->translate($page->getLabel()) ?>
            </a>
        </li>
        <?php else: ?>
        <li class="dropdown <?php if ($page->isActive(true)) echo ' active';?>">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                <?php if ($page->get('icon')):?>
                <i class="<?php echo $page->get('icon');?>"></i>
                <?php endif;?>
            <span><?php echo $this->translate($page->getLabel()) ?>&nbsp;<b class="caret"></b></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 if ($child->getTitle()) echo 'title="'.$this->translate($child->getTitle()).'"'; ?>>
                        <?php if ($child->get('icon')):?>
                        <i class="<?php echo $child->get('icon');?>"></i>
                        <?php endif;?>
                        <?php echo $this->translate($child->getLabel()) ?>
                    </a>
                </li>
            <?php endforeach ?>
            </ul>
         </li>
        <?php endif ?>
        <?php $count++ ?>
    <?php endforeach ?>
</ul>

在layout.phtml中,声明新模板:

//Préparation du menu 
$partialMenu = array('navigation/topnav.phtml','default');
$this->navigation('navigation')->menu()->setPartial($partialMenu);

我希望它会帮助你。

抱歉我的英语,我的英语不流利