private function _getNav()
{
//先获祖先节点,然后获取兄弟节点
$nav_model=M('nav');
$id=I('get.n_id',0);
$condition['is_show']=1;
$navList=$nav_model->where($condition)->select();
// dump($navList);
$parent=$this->_getParent($navList,$id);//查找一级节点
$sonList=$this->_getSons($navList,$parent['id']);
return array('parent'=>$parent,'sons'=>$sonList);
}
/**
* [getParent 找到一级节点]
* @Author:wty
* @DateTime:2016-05-01T17:14:10+0800
* @return [type] [description]
*/
private function _getParent($arr,$son)
{
$first=array();
foreach ($arr as $key => $value) {
if($value['id']==$son&&$value['parentid']!=0){
$first=$this->_getParent($arr,$value['parentid']);
}
if($value['id']==$son&&$value['parentid']==0){
$first=$value;
}
}
return $first;
}
/**
* [getSons 子孙查找]
* @Author:wty
* @DateTime:2016-05-01T17:14:48+0800
* @return [type] [description]
*/
private function _getSons($arr,$parentid)
{
$first=array();
foreach ($arr as $key => $value) {
if($value['parentid']==$parentid&&$value['parentid']!=0){
$first[]=$value;
}
}
return $first;
}