主菜单项位于下拉菜单中

时间:2014-11-11 12:36:59

标签: php css twitter-bootstrap

好的,让我尽我所能解释这个问题。

我有一个JSON(我转换为数组)菜单,看起来像这样

Array ( [0] => Array ( [_id] => MongoId Object ( [$id] => 5443672bf5421896488b4567 ) [title] => Home [menutask] => url [task] => home [menulevel] => 0 [order] => 1 ) [1] => Array ( [_id] => MongoId Object ( [$id] => 54545bcef542189b4c8b4567 ) [title] => About [menutask] => page [task] => 54545bb8f54218834c8b4567 [menulevel] => 0 [order] => 2 ) [2] => Array ( [_id] => MongoId Object ( [$id] => 5443670af542187a488b4567 ) [title] => Projects [menutask] => Select [task] => projects [menulevel] => 0 [order] => 3 [submenu] => Array ( [0] => Array ( [title] => iPetFindr [menutask] => page [task] => 544364c0f542186c438b4567 ) ) ) [3] => Array ( [_id] => MongoId Object ( [$id] => 54620183f542187e658b4567 ) [title] => Contact [menutask] => page [task] => 54545bb8f54218834c8b4567 [menulevel] => 0 [order] => 4 ) )

然后我有我的PHP代码应该知道,除非子菜单设置也不是空的,应该将其列为主菜单,如家庭和项目,但如果像项目一样,它有一个子菜单,它列出项目下的子菜单 - 哪个有效。但似乎当我尝试将项目之后的联系人或任何其他菜单项添加到项目下拉列表的底部时。

现在这可能是一件非常简单的事情,就像我可以忘记关闭一些明智的东西。但我无法看到我的错误,所以我想我会发布我的PHP代码,看看我犯了什么错误。

这是完整的导航栏 - 我使用bootstrap作为css框架(对不起代码量)

<nav class="navbar navbar-inverse" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
           <div class="navbar-inner">
            <div class="container">
            <div class="navbar-header" style="margin:0;">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" rel="home"  href="#"><img src="//<?=SITEURL;?>/templates/main/images/small-logo.png" width="40" height="40" alt="RussellHarrower.com"></a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                <?php
                print_r($menu);
                    foreach($menu as $item){
                      if(empty($item['submenu'])){
                        if(MongoId::isValid ($item['task']) == 1)
                        {
                          $link = self::fetch_link($item['task']);

                        }
                        else
                        {
                          $link = array();
                          $link['url'] = $item['task'];
                        }
                      ?>
                        <li <?php if(URI_1 == $link['url']){echo 'class="active"';}?>><a href="//<?=SITEURL;?>/<?=$link['url'];?>"><?=$item['title'];?></a></li>
                      <?php
                      }
                      else
                      {
                        if(MongoId::isValid ($item['task']) == 1)
                        {
                          $link = self::fetch_link($item['task']);

                        }
                        else
                        {
                          $link = array();
                          $link['url'] = $item['task'];
                        }
                      ?>
                            <li class="dropdown
                            <?php if(URI_1 == $link){
                               echo ' active';
                            }?>
                            ">
                              <a href="//<?=SITEURL;?>/<?=$link['url'];?>" class="dropdown-toggle" data-toggle="dropdown"><?=$item['title'];?><span class="caret"></span></a>
                                  <ul class="dropdown-menu" role="menu">
                                    <?php
                                          foreach($item['submenu'] as $submenu)
                                          {
                                            if(MongoId::isValid ($submenu['task']) == 1)
                                            {
                                              $link = self::fetch_link($submenu['task']);
                                            }
                                            else
                                            {
                                            $link = array();
                                            $link['url'] = $submenu['task'];
                                            }
                                            ?>
                                            <li
                                            <?php
                                            if(URI_1 == $link){
                                               echo 'class="active"';
                                            }

                                            echo '><a href="//'; print SITEURL."/".$link['url']; echo'">';
                                            print $submenu['title'];
                                            echo '</a></li>';

                                          }
                                    ?>
                            </li>
                        <?php
                      }
                    }
                    ?>

                </ul>
        </div>
        </div>
        </nav>

0 个答案:

没有答案