【问题标题】:create a menu hierarchy bootstraps with PHP and mysql使用 PHP 和 mysql 创建菜单层次引导程序
【发布时间】:2016-06-14 08:23:49
【问题描述】:

对不起我的英语不好 我有一个表格菜单: here is my table menus

所以我想问一下,如何根据表中的数据制作代码.. 或者也许有人在这方面有任何参考?

这是我尝试过但仍然失败的代码

public function all_tree()
    {
        $nodes = $this->db->get('alus_menu_group')->result();
        return $this->getChildren($nodes, 0, 0);
    }

public function getChildren($nodes ,$pid = 0, $depth = 0)
   {
      $tree = array();

      foreach($nodes as $node) {

         if ($node->menu_parent == $pid) {

            if($depth == 0)
            {
               if(!$this->getChildren1($nodes, $node->menu_id, ($depth + 1)))
               {
                  $hasil = "<li class='dropdown'>
                      <a href='#' class='dropdown-toggle' data-toggle='dropdown'>".$node->menu_nama."</a>
                      <ul class='dropdown-menu'>";
                  $hasil .= $this->getChildren($nodes, $node->menu_id, ($depth + 1));

               }else
               {
                  $hasil = "<li><a href=".base_url().$node->menu_uri." target=".$node->menu_target.">".$node->menu_nama."</a></li>";      
               }
            }
            if($depth == 1)
            {
               if(!$this->getChildren1($nodes, $node->menu_id, ($depth + 1)))
               {
                  $hasil = "<li class='dropdown-submenu'>
                      <a href='#'>".$node->menu_nama."</a>
                      <ul class='dropdown-menu'>";
                  $hasil .= $this->getChildren($nodes, $node->menu_id, ($depth + 1));

               }else
               {
                  $hasil = "<li><a href=".base_url().$node->menu_uri." target=".$node->menu_target.">".$node->menu_nama."</a></li></ul></li>";      

               }

            }if ($depth == 2) 
            {
               $hasil = "<li><a href=".base_url().$node->menu_uri." target=".$node->menu_target.">".$node->menu_nama."2</a></li></ul></li></ul></li>";   

            }
            $tree[]   = $hasil;
         }

      }
      return $tree;
   }
    public function view()
{
$data['tree'] = $this->all_tree();
$this->load->view('index.php',$data);
}

然后在 view.php 中我正在做 foreach 。 有人可以帮忙吗?谢谢

【问题讨论】:

    标签: mysql oop hierarchy codeigniter-3


    【解决方案1】:

    此链接可能会对您有所帮助。

    Link from code.tutsplus.com

    您只需要根据上面链接的html制作动态数据。

    希望对你有帮助!!

    【讨论】:

      【解决方案2】:

      答案是这样的 -> http://pastebin.com/GAFvSew4 谢谢大家

      【讨论】:

        猜你喜欢
        • 2010-10-03
        • 2021-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多