Share a Thinkphp code for Infinitus classification

Source: Internet
Author: User
Unlimited classification is too important. But I can't write it. what should I do? This article will teach you how to write an unlimited classification. The most important thing is to grasp the logic of Infinitus classification, so it is much easier to write.

Unlimited classification is too important. But I can't write it. what should I do?

This article will teach you how to write an unlimited classification.

The most important thing is to grasp the logic of Infinitus classification, so it is much easier to write.

First look at the database table: xp_cate

Controller: CateAction. class. php

Class 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 a topic
Function add (){
$ Cate = new CateModel (); if ($ vo = $ cate-> create ()){
If ($ cate-> add ()){
$ This-> success ('column added successfully ');
} Else {
$ This-> error ('add topic failed ');
}
} Else {
$ This-> error ($ cate-> getError ());
}
}}
?>

Model: CateModel. class. php

Class CateModel extends Model {// table xp_cate in the corresponding database
Protected $ _ 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 subclass path adds the parent class id to the parent class path.
}
Return $ data;
}
}
?>

Template: index.html

The result is as follows:

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.