public function search() { $fields = 'menu_id, pid, title, ctrl_name, sort, create_uname, create_time'; $query = $this->db->select($fields)->order_by('pid asc, sort asc')->get($this->table); $list = $query->result_array(); $tree = array(); create_tree_list($list, $tree, 0, 0, array('id_key' => 'menu_id', 'pid_key' => 'pid')); return array_values($tree); }
public function index() { $user_id = $this->session->userdata('user_id'); $this->load->model('sys/pms_model'); $is_admin = $this->session->userdata('is_admin'); //$list =$this->session->userdata('user_pms'); $list = $this->pms_model->get_user_menu_pms($user_id, $is_admin); $tree = array(); create_tree_list($list, $tree, 0, 0, array('id_key' => 'menu_id', 'pid_key' => 'pid')); // var_dump($this->session->all_userdata());exit; $this->load->view('index', array('app_menu' => $tree)); }
function create_tree_list(&$input, &$output, $pid = 0, $level = 0, $config = array('id_key' => 'id', 'pid_key' => 'pid')) { $id_key = $config['id_key']; $pid_key = $config['pid_key']; $num = count($input); for ($i = 0; $i < $num; $i++) { if ($input[$i][$pid_key] == $pid) { $input[$i]['level'] = $level; $input[$i]['is_leaf'] = true; $output[$input[$i][$id_key]] = $input[$i]; if ($pid > 0) { $output[$pid]['is_leaf'] = false; } create_tree_list($input, $output, $input[$i][$id_key], $level + 1, $config); } } }
/** * 返回分店列表 * @return [type] [description] */ public function get_list() { $query = $this->db->select($this->fields)->order_by('pid asc, sort asc')->get($this->table); $list = $query->result_array(); $tree = array(); create_tree_list($list, $tree, 0, 0, array('id_key' => 'id', 'pid_key' => 'pid')); return array_values($tree); }