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 => ; $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 ...