[原创]ThinkPhp实现无限极分类,无限级分类

前言:

作者在学习的时候发现这个无限极分类不是很好理解,在网上找了一下,然后汇总/思考/整理/(好像很很多步骤.其实就是那么一瞬间啦)如下代码利用ThinkPhp实现无限极分类


数据表

WxjController.class.php

namespace Admin\Controller;
use Think\Controller;
class WxjController extends Controller{
	public function index(){
		$wxjModel = D('wxj');
		$wxj = $wxjModel->getTree(); 
		$this->assign('wxj',$wxj);
		$this->display();
	}
}

WxjModel.class.php

namespace Admin\Model;
use Think\Model;
class WxjModel extends Model{
	public function getTree($p=0,$lv=0){
		$tree = $this->select();
		$t = array();
		foreach ($tree as $k => $v){
			if($v['pid'] == $p){
				$v['lv'] = $lv;
				$t[] = $v;
				$t = array_merge($t,self::getTree($v['id'],$lv+1));
			}
		}
		return $t;
	}
}

index.html(很抱歉不知道为何html代码不能显示,所以...)

最后实现效果图

完~~~

Comments : 11

  1. 作者
    作者 回复

    唯一缺点就是没有注释,那就让他成为缺点吧!!!

  2. Zynga's free casino games are widely available.

  3. KelAssure

    Propecia Ciao Prix Propecia Nancy canadian generic levitra Propecia Depression Fish Antibiotics Amoxicillin Kamagra Jelly 100mg cialis overnight shipping from usa Propecia Andamento Libido Levitra Italia online pharmacy Levitra Kaufen Mit Rezept Order Page Buy Cialis Usa Fedex Provera Us Overnight Shipping C.O.D. Online order accutane online no prescription Levitra Farmaco Equivalente Kopa Lasix cialis generic Cialis Nuevo Viagra Sildenafil Pfizer Lasix Online Uk Buy Viagra Overnight viagra Cialis Generico Commenti

  4. Lesmeerty

    Zithromax To Buy Uk viagra prescription Ricetta Cialis Achat Cialis France

  5. EllWeen

    Online Cialis Pharmacy buy cialis Can You Buy Genuine Viagra Online 47 Fedex Viagra Generic

  6. EllWeen

    Amoxicillin Cost viagra Penegra Mail order isotretinoin mastercard Amoxicilina Where To Buy Medication

  7. Lesmeerty

    Legally Bentyl Ups Drugs 20 Mg Cialis Side Effects Cialis Viagra Et De Dapoxetine Canadian Vigra

  8. StevOwetlY

    Nolvadex Achat Buy Cialis Acheter Cialis Effet

  9. Matbeaumn

    Viagra Sublingual Tablet 83 http://cialibuy.com - Buy Cialis Buy Chlamydia Pills Online In Usa Cialis Avelox Vs Amoxicillin

  10. Cialis

    Hi colleagues, its impressive article regarding cultureand fully explained,
    keep it up all the time.

  11. Lesmeerty

    Onlinedrugstore http://abuycialisb.com - Buy Cialis Cialis Pagamento Alla Consegna cialis 5 mg Canada Pharmacy For Methotrexate

发表留言

人生在世,错别字在所难免,无需纠正。