Thinkphp Infinite Class Code, thinkphp Unlimited Code _php Tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.