Provides various official and user-released code examples and code reference. You are welcome to exchange and learn the most efficient unlimited Menu Generation Method.
$ Menu = M ('menu ');
$ Items = $ Menu-> order ('pid, sort ')-> select (); // sort by pid in ascending order to ensure that the parent node is in the front, the child node is behind. Sort is the display order of nodes at the same level.
$ Menu = array ();
Foreach ($ items as $ v ){
$ Menu [$ v ['_ id'] = $ v;
$ Menu [$ v ['_ id'] ['items'] = array (); // items stores all the subnodes of the current node.
If ($ v ['pid ']! = 0 ){
$ Menu [$ v ['pid '] ['items'] [$ v ['_ id'] = & $ menu [$ v [' _ id'];
}
}
Foreach ($ menu as $ k => $ v ){
If ($ v ['pid ']! = 0 ){
Unset ($ menu [$ k]);
}
}OT contains the encapsulation of this function. The list_to_tree function in the Application \ Common \ function. php file and function. php file contains many function functions.
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB