function get_treepath($tree, $level = 0, $current_position, $treepath = array('stop' => 0)) { foreach ($tree as $leaf) { if ($treepath['stop'] == 1) { return $treepath; break; } if (empty($treepath['stop'])) { $treepath[$level] = $leaf; if ($current_position == $leaf['position']) { $treepath['stop'] = 1; //TODO 优化 后续考虑数据库 menu 增加 level 或者把 创建节点的时候 把树路径写入到 unset($treepath[$level + 1]); unset($treepath[$level + 2]); unset($treepath[$level + 3]); unset($treepath[$level + 4]); break; } else { $treepath = get_treepath($leaf['submenu'], $level + 1, $current_position, $treepath); } } } return $treepath; }
private function _init_position() { $login_user_menu = getglobal('login_user_menu'); //DEBUG 通过mod 查询当前mod下的子菜单树形数组 if ($this->init_position && $this->var['mod'] && !empty($login_user_menu)) { foreach ($login_user_menu[1]["submenu"][4]["submenu"] as $key => $value) { if (!empty($value['position']) && $value['position'] == $this->var['mod']) { $current_mod = array('name_var' => $value['name_var'], 'left_menu' => $value['submenu']); } } } setglobal('current_mod', $current_mod); //DEBUG 设置用户当前路径 breadcrumb, 取第一维数组为轨迹路径 $current_position = $this->var['mod'] . '_' . $this->var['action'] . '_' . $this->var['do']; $treepath = array(); $treepath = get_treepath($current_mod['left_menu'], 0, $current_position); unset($treepath['stop']); setglobal('breadcrumb', $treepath); }