thinkphp栏目中实现无极限分类ThinkPHP教程

/ / 2016-06-26   阅读:2491
无极限分类应用广泛,作为一个开发者,想必会经常遇到,其实无极限分类用一个递归就可以实现,理解之后,也就只要5分钟就可以写出这个功能了。 //栏目管理 public function in...

无极限分类应用广泛,作为一个开发者,想必会经常遇到,其实无极限分类用一个递归就可以实现,理解之后,也就只要5分钟就可以写出这个功能了。



//栏目管理

public function index(){

  $cat = M("Category");

  $catlist = $cat->where("catid>1")->select();

  $newArr = $this->getCategory($catlist);

  //dump($newArr);

  $this->assign("catlist",$newArr);

  $this->display();

}


// 递归调用栏目

public function getCategory($catlist,$asmenu='0',$html='——',$level='0'){

  $arr = array();

  foreach($catlist as $val){

    if($val['asmenu']==$asmenu){

      $val['html'] = str_repeat($html,$level);

      $arr[] = $val;

      $arr = array_merge($arr,self::getCategory($catlist,$val['catid'],$html,$level+1));

      //dump($arr);

      //exit();

    }  

  }

  return $arr;

}

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈