_dir_table where user_id=$..."/>
您好,登錄后才能下訂單哦!
//完整的目錄結(jié)構(gòu) function get_dir_tree($uid,$from_dir=0){ $sql = "select dir_id,dir_name,depth,p_id from $this->_dir_table where user_id=$uid and is_del=0 and dir_id>=$from_dir"; $res = $this->db->query($sql)->result_array(); if(!isset($res[0])){ return null; } $this->load->helper('array'); //獲取depth區(qū)間 $max_depth = 0; foreach($res as $dps => $d){ if($d['depth']>$max_depth){ $max_depth = $d['depth']; } } for($i=$max_depth;$i>=0;$i--){ //處理成樹形,子集存在child里,有沒有自己看有沒有child字段 foreach($res as $key=>$val){ if($val['depth']==$i){ foreach($res as $k=>$v){ if($val['p_id']==$v['dir_id']){ $v['child'][] = $val; $res[$k] = $v; unset($res[$key]); } } } } } $return = $this->has_child_then_add_ul($res); $html="<ul> <!-- 第一級 --> <li class=''><div class='tree-title'><a href='javascript:void(0)' class='icon icon-add'></a><a href='javascript:void(0)' class='shareItem fold'>全部文件</a></div>"; $html.=$return."</li></ul>"; return $html; } private function has_child_then_add_ul($res,$html='',$collaps_times=1){ $collaps = 15;//前端寫的是m_l_15, m_l_30 這樣的 , 15為一個單位,跟前端商定就好 $indent = $collaps_times*$collaps; $has_sibling = 0; $ul_begin = "<ul class='undis'>"; $ul_end = "</ul>"; $li_begin = "<li><div class='tree-title'><a href='javascript:void(0)' class='icon icon-add m_l_%d'></a><a href='javascript:void(0)' class='shareItem fold'>%s</a></div>";//%s處是dir_name // $li_begin = "<li>%s";//%s處是dir_name $li_end = "</li>"; $count_li_end = $count_ul_end = 0; foreach($res as $key=>$val){ if(0==$key){ $html.=$ul_begin; } $html.=sprintf($li_begin,$indent,$val['dir_name']); $count_li_end++; if(isset($val['child'])){ $html = $this->has_child_then_add_ul($val['child'],$html,$collaps_times+1); } $html.=$li_end; if(!isset($res[$key+1])){ $html.=$ul_end; } } return $html ; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。