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

Zend 2 Navigation add <i> before label name

我有以下导航数组,但现在我想要在我的标签前加上一个。

如何以及在哪里添加这个?

输出必须是:

<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)

您必须为您的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);

希望对你有所帮助

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