Thinkphp Infinite Class Code, thinkphp Unlimited Code
This article on 1.1 points to teach you to write an infinite class classification out, in fact, master a knowledge, the most important thing is to master the logic of Infinite class classification, then write it up is much easier.
First look at the database table: xp_cate
Controller: CateAction.class.php
<?phpclass Cateaction extends Action{function index () {$cate =m (' Cate '); $list = $cate->field ("Id,name,pid,path, Concat (Path, '-', id) as Bpath ")->order (' Bpath ')->select (), foreach ($list as $key = + $value) {$list [$key] [' Count ']=count (Explode ('-'), $value [' Bpath ']);} $this->assign (' alist ', $list); $this->display ();} Add Column function Add () {$cate =new Catemodel (), if ($vo = $cate->create ()) {if ($cate->add ()) {$this->success (' Add column Success ');} else{$this->error (' Add column failed ');}} else{$this->error ($cate->geterror ());}}? >
Model: CateModel.class.php
<?phpclass Catemodel extends model{//corresponds to the table in the database xp_cateprotected $_auto=array (Array (' path ', ' TCLM ', 3, ' callback '),); function Tclm () {$pid =isset ($_post[' pid '])? ( int) $_post[' pid ']:0;echo ($pid); if ($pid ==0) {$data = 0;} else{$list = $this->where ("id= $pid")->find (); $data = $list [' path ']. ' -'. $list [' id '];//the path of the parent class and the Id}return $data of the parent class;}}? >
Template: index.html
The results appear as follows:
There is no logic to master the Infinite Class classification, the above-mentioned thinkphp infinite classification code, I hope that everyone's learning is helpful.
http://www.bkjia.com/PHPjc/1070271.html www.bkjia.com true http://www.bkjia.com/PHPjc/1070271.html techarticle thinkphp Unlimited Class code, thinkphp Unlimited code This article on 1.1 points to teach everyone to write an infinite class classification out, in fact, master a knowledge, the most important thing is to master the Infinite class classification ...