麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

TP框架實(shí)現(xiàn)獲取無限極分類的樹

2019-11-11 05:16:09
字體:
供稿:網(wǎng)友
看了很多別人的實(shí)現(xiàn)方法,都沒看明白,所以自己寫一個(gè)。
數(shù)據(jù)庫結(jié)構(gòu)如下:
model里面這樣子
<?php/** * Created by PhpStorm. * User: 王柏建 * Date: 2016/10/09 * Time: 11:32 */namespace Api/Model;use Think/Model;class TypeModel extends Model{    //通過admin_id獲取分類    public static function getTypeByAdminId($admin_id){        return M('type')->where(array("admin_id"=>$admin_id))->select();    }    //通過條件獲取一個(gè)分類    public static function getTypeByWhere($where){        return M('type')->where($where)->find();    }        //通過條件獲取部分分類    public static function getAllTypeByWhere($where){        return M('type')->where($where)->field("clothes_type_id,clothes_type_father_id,clothes_type_name,clothes_type_icon_url")->select();    }}
最后這里是controller里面的寫法。
<?phpnamespace Api/Controller;use Api/Model/TypeModel;use Think/Controller;class TreeController extends Controller {    //記錄層    public $div = [];    //記錄樹    public $tree = [];    //返回樹    public function returnTree(){        $tree = [];        //獲取目前已經(jīng)有的結(jié)構(gòu)        $this->getChild(0);  //從第一級開始        //dump($this->tree);   //這里是輸出數(shù)組        $this->AjaxReturn($this->tree,"json");   //輸出json    }    //獲取某個(gè)分類的子分類以及下面的服飾    public function getChild($clothes_type_father_id){        $types = TypeModel::getAllTypeByWhere(array("clothes_type_father_id"=>$clothes_type_father_id));        if(!$types){            array_pop($this->div);            return;        }        if($clothes_type_father_id == 0){            $this->div[] = 0;        }        else{            $this->div[] = TypeModel::getTypeByWhere(array('clothes_type_id'=>$clothes_type_father_id))['clothes_type_id'];        }        //將獲取到的東西放到$this->tree里面        $this->putData($this->tree,$this->div,$types);        //循環(huán)這一級里面的類,再獲取其子類和下面的服飾        foreach($types as $t){            $this->getChild($t['clothes_type_id']);        }    }    //插入數(shù)據(jù)到特定下標(biāo)    public function putData(&$array,$down,$data){        $j = [];        $k = 0;        foreach($down as $d){            if($j == null){                $j[$k] = &$array[$d];            }            else{                $j[$k] = &$j[$k++][$d]['son'];            }        }        $count = count($j)-1;        foreach($data as $d){            $j[$count][$d['clothes_type_id']] = $d;        }        unset($j);        unset($k);    }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产四区 | 中文字幕涩涩久久乱小说 | 精品成人网 | 99精品国产成人一区二区 | 久久久激情网 | 黑人一区二区三区四区五区 | 日韩色视频在线观看 | 国产毛毛片一区二区三区四区 | 日本精品黄色 | 黄在线免费看 | 宅男视频在线观看免费 | 激情小说图 | 欧美一级α| 欧美一区2区三区4区公司二百 | 欧美在线观看视频一区 | 日韩黄色av | 日本欧美国产 | 一级做a爰性色毛片免费 | 亚洲福利视频52 | 在线看免费观看av | 国内精品久久久久久久星辰影视 | 久草在线综合网 | 99最新地址 | 免费高清一级欧美片在线观看 | 毛片免费一区二区三区 | 又黄又爽又色无遮挡免费 | 亚洲成人精品在线 | 最新午夜综合福利视频 | 久久精品小短片 | cosplay裸体福利写真 | sm高h视频| 欧美成年人视频在线观看 | 国产精品免费一区二区三区都可以 | 免费观看一级黄色片 | 国产毛片自拍 | 1区2区3区国产 | 草操视频| hdjapanesemassagehd日本| 欧美综合在线观看视频 | 亚洲精品无码不卡在线播放he | 免费看毛片的网站 |