Thinkphp unlimited classification code and thinkphp unlimited code. Thinkphp unlimited classification code, thinkphp unlimited code this article will teach you to write an unlimited classification, in fact, to master a knowledge, the most important thing is to master the unlimited classification of Thinkphp code, thinkphp unlimited code
In this article, we will teach you how to write an infinite classification. In fact, to master a knowledge, the most important thing is to master the logic of an infinite classification, so it is much easier to write it.
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 function add () {$ cate = new CateModel (); if ($ vo = $ cate-> create () {if ($ cate-> add () {$ this-> success ('add column Succeeded ');} else {$ this-> error ('failed to add a topic ');}} else {$ this-> error ($ cate-> getError () ;}}}?>
Model: CateModel. class. php
<? Phpclass CateModel extends Model {// The Table xp_cateprotected $ _ auto = array ('path', 'tclm', 3, 'callback') in the database '),); 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 subclass is the path of the parent class plus the id of the parent class.} return $ data ;}}?>
Template: index.html
The result is as follows:
Have you mastered the infinite classification logic? the thinkphp infinite classification code shared above is helpful for your learning.
In this article, we will teach you how to write an unlimited classification. In fact, you must master a knowledge. The most important thing is to master an unlimited classification...