PHP中的多级菜单与循环

时间:2017-04-09 07:59:57

标签: php

*我需要在主题下另一个级别菜单。请帮忙,因为2周以来我一直在努力帮助我理解循环*

PHP和HTML菜单代码请查看以下内容

      <!-- Sidebar Menu -->

      <ul class="sidebar-menu">
          <?php
          if($users->role == "admin" AND $users->customPermissionsType == "custom"){
              $userPerm = $users->customPermissionsAsJson();
              $performPermScan = true;
          }
          while (list($key, $value) = each($panelInit->panelItems)) {
              if(isset($value['activated']) AND !strpos($panelInit->settingsArray['activatedModules'],$value['activated']) ){ continue;  }
              if(!in_array($users->role, $value['permissions'])){
                  continue;
              }
              if(isset($performPermScan) AND isset($value['cusPerm']) AND $value['cusPerm'] != ""){
                  if(!in_array($value['cusPerm'],$userPerm)){
                      continue;
                  }
              }
              echo "<li ";
              if(isset($value['children'])){
                  echo "class='treeview'";
              }
              echo ">";
              echo "<a ";
              if(!isset($value['children'])){
                  echo "class='aj'";
              }
              if(isset($value['url'])){
                  echo " href='".URL::to($value['url'])."'";
              }
              echo ">";
              echo "<i class='".$value['icon']."'></i><span>";
              if(isset($panelInit->language[$value['title']])){
                  echo $panelInit->language[$value['title']];
              }else{
                  echo $value['title'];
              }
              echo "</span>";
              if(isset($value['children'])){
                  echo "<i class='fa fa-angle-left pull-right leftMenuExpand'></i>";
              }
              echo "</a>";

              if(isset($value['children'])){
                  echo '<ul class="treeview-menu">';
                  while (list($key2, $value2) = each($value['children'])) {
                      if(isset($value2['activated']) AND !strpos($panelInit->settingsArray['activatedModules'],$value2['activated']) ){ continue;  }
                      if(!in_array($users->role, $value2['permissions'])){
                          continue;
                      }
                      if(isset($performPermScan) AND isset($value2['cusPerm']) AND $value2['cusPerm'] != ""){
                          if(!in_array($value2['cusPerm'],$userPerm)){
                              continue;
                          }
                      }
                      echo "<li>";
                      echo "<a class='aj' href='".URL::to($value2['url'])."'>";
                      echo "<i class='".$value2['icon']."'></i> ";
                      if(isset($panelInit->language[$value2['title']])){
                          echo $panelInit->language[$value2['title']];
                      }else{
                          echo $value2['title'];
                      }
                      echo "</a>";
                      echo "</li>";
                  }
                  echo "</ul>";
              }

              echo "</li>";
          }
          ?>
      </ul>
    </section>
    <!-- /.sidebar -->

这是我在这里定义菜单的主菜单功能

public function __construct(){
    $this->panelItems = array(
                                "schooladmintasks"=>array("title"=>"School Admin Panel ","icon"=>"fa fa-institution","activated"=>"schadminparentAct","permissions"=>array('admin','teacher','student','parent'),                                   
                                                    "children"=>array(
                                                        "classes"=>array("title"=>"classes","url"=>URL::to('#/classes'),"icon"=>"fa fa-check","permissions"=>array('admin') ),
                                                        "sections"=>array("title"=>"sections","url"=>URL::to('#/sections'),"icon"=>"fa fa-check","permissions"=>array('admin') ),
                                                        "subjects"=>array("title"=>"Subjects","url"=>URL::to('#/subjects'),"icon"=>"fa fa-check","cusPerm"=>"Subjects","permissions"=>array('admin') ),                                                         

                                                    )
                                ),);

1 个答案:

答案 0 :(得分:0)

你试过吗

public function __construct(){
$this->panelItems = array(
                            "schooladmintasks"=>array("title"=>"School Admin Panel ","icon"=>"fa fa-institution","activated"=>"schadminparentAct","permissions"=>array('admin','teacher','student','parent'),                                   
                                                "children"=>array(
                                                    "classes"=>array("title"=>"classes","url"=>URL::to('#/classes'),"icon"=>"fa fa-check","permissions"=>array('admin') ),
                                                    "sections"=>array("title"=>"sections","url"=>URL::to('#/sections'),"icon"=>"fa fa-check","permissions"=>array('admin') ),
                                                    "subjects"=>array("title"=>"Subjects","url"=>URL::to('#/subjects'),"icon"=>"fa fa-check","cusPerm"=>"Subjects","permissions"=>array('admin') ),                   

"thing"=>array("title"=>"Thing","url"=>URL::to('#/thing'),"icon"=>"fa fa-check","cusPerm"=>"Thing","permissions"=>array('admin') ),  


                                                )
                            ),);