Recursive add-on implements tree and infinite menu _php tutorial

Source: Internet
Author: User
Data= r::getall (' select * from menu '); $this->teamdata (); if ($this->rdata) return $this->rdata; return false; } function AddMenu ($data) {foreach ($data as $key = + $value) {if ($value = = ' Please fill in the contents!) ') $data [$key]= '; if ($data) {$menu = R::d ispense (' menu '), $menu->pid = $data [' pid ']; $menu->name = $data [' name ']; $menu->url = $d ata[' url ']; $menu->icon = $data [' Icon ']; $id = R::store ($menu); return $id; }}//Returns the JSON string public function Getjsonmenu () {$data = $this->getchild (1); $this->jdata = $data; $this->recursiv E ($this->jdata); Return Json_encode ($this->jdata); }//recursive function implementation of the continuous generation of sub-nodes, using a reference, feeling that the reference is the Tathagata God pen, otherwise the implementation is too complex public function recursive (& $data = Array ()) {foreach ($data as $key =&gt ; $value) {$data [$key] [' Children ']= $this->getchild ($value [' id ']), $tmp = & $data [$key] [' children ']; if ($tmp) {$ This->recursive ($TMP); }}}//organization data, the Select to generate a tree returns an array//array in the form of a public function teamdata ($pid =1) {foreach ($this->data as $key + = $valu e) {if ($value[' pid ']== $pid) {$this->level++; Array_push ($this->rdata, Array (' name ' = = $value [' name '], ' level ' =>$ This->level, ' id ' = $value [' id '])); $tmpdata = $this->teamdata ($value [' id ']); if (! $tmpdata) {$this->level--; continue;}} }}//According to the PID, take the following sub-data public function Getchild ($pid) {$data = R::getall ("Select * from menu where pid = {$pid}"); $tmpdata = Array (); if ($data) {foreach ($data as $key = + $value) {$tmpdata [$key] [' id '] = $value [' id ']; $tmpdata [$key] [' icon '] = $value [' IC On ']; $tmpdata [$key] [' text '] = $value [' name ']; $tmpdata [$key] [' url '] = $value [' url ']; $tmpdata [$key] [' children '] = array (); }} return $tmpdata; } }

http://www.bkjia.com/PHPjc/477141.html www.bkjia.com true http://www.bkjia.com/PHPjc/477141.html techarticle PHP class K_model_menu_menu {Private $data = array (), Private $rdata = Array (), Private $jdata = Array (); private $l Evel = 0; Private $paret = Array (); function getOption ($type = P ...

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