Zend 2导航添加<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>

Array module config:

 '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。php模板,这里是我在以前的项目中使用的。小心!有很多不同,因为我用了一些其他的选项。这只是样品。

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

在你的布局。php,声明新模板:

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

我希望它能帮助你。

对不起,我的英语不是很流利