抱歉我的英语不好 我有一个餐 table 菜单: 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 - 使用 PHP 和 mysql 创建菜单层次结构 Bootstrap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37806698/