所以我想问一下,如何根据表中的数据制作代码的过程。 或者也许有人在这方面有任何提及?
这是我尝试但仍然失败的代码
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。 有人可以帮忙吗? thnks