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: