84669 orang belajar
152542 orang belajar
20005 orang belajar
5487 orang belajar
7821 orang belajar
359900 orang belajar
3350 orang belajar
180660 orang belajar
48569 orang belajar
18603 orang belajar
40936 orang belajar
1549 orang belajar
1183 orang belajar
32909 orang belajar
Seperti berikut
Versi Cina
Saya mendapati ralat. $menu dalam kaedah tambah hendaklah ditukar kepada $results
Salah $this->assign('menu',$menus);
Correct $this->assign('menu ' ,$hasil);
<?php /** 角色管理 */ namespace app\admins\controller; use app\admins\controller\BaseAdmin; class Roles extends BaseAdmin { //角色列表 public function index(){ $data['roles']=$this->db->table('admin_groups')->lists(); $this->assign('data',$data); return $this->fetch(); } //角色添加 public function add(){ $menus_list = $this->db->table('admin_menus')->where(array('status'=>0))->cates('mid'); $menus = $this->gettreeitems($menus_list); $results = array(); foreach ($menus as $value) { $value['children'] = isset($value['children'])?$this->formatMenus($value['children']):false; $results[] = $value; } var_dump($results); $this->assign('menus',$menus); return $this->fetch(); } private function gettreeitems($items){ $tree = array(); foreach ($items as $item){ if(isset($items[$item['pid']])){ $items[$item['pid']]['children'][] = &$items[$item['mid']]; } else{ $tree[] = &$items[$item['mid']]; } } return $tree; } private function formatMenus($items,&$res=array()){ foreach ($items as $item) { if(!isset($item['children'])){ $res[] = $item; }else{ $tem = $item['children']; unset($item['children']); $res[] = $item; $this->formatMenus($tem,$res); } } return $res; } }
array (size=4) 0 => array (size=9) 'mid' => int 1 'pid' => int 0 'ord' => int 0 'title' => string '管理员管理' (length=15) 'controller' => string '' (length=0) 'method' => string '' (length=0) 'ishidden' => int 0 'status' => int 0 'children' => array (size=4) 0 => array (size=8) 'mid' => int 4 'pid' => int 1 'ord' => int 0 'title' => string '管理员列表' (length=15) 'controller' => string 'Admin' (length=5) 'method' => string 'index' (length=5) 'ishidden' => int 0 'status' => int 0 1 => array (size=8) 'mid' => int 17 'pid' => int 4 'ord' => int 0 'title' => string '角色列表' (length=12) 'controller' => string 'Admin' (length=5) 'method' => string 'test' (length=4) 'ishidden' => int 0 'status' => int 0 2 => array (size=8) 'mid' => int 5 'pid' => int 1 'ord' => int 0 'title' => string '管理员添加' (length=15) 'controller' => string 'Admin' (length=5) 'method' => string 'add' (length=3) 'ishidden' => int 1 'status' => int 0 3 => array (size=8) 'mid' => int 6 'pid' => int 1 'ord' => int 0 'title' => string '管理员保存' (length=15) 'controller' => string 'Admin' (length=5) 'method' => string 'save' (length=4) 'ishidden' => int 1 'status' => int 0 1 => array (size=9) 'mid' => int 2 'pid' => int 0 'ord' => int 0 'title' => string '权限管理' (length=12) 'controller' => string '' (length=0) 'method' => string '' (length=0) 'ishidden' => int 0 'status' => int 0 'children' => boolean false 2 => array (size=9) 'mid' => int 3 'pid' => int 0 'ord' => int 0 'title' => string '系统设置' (length=12) 'controller' => string '' (length=0) 'method' => string '' (length=0) 'ishidden' => int 0 'status' => int 0 'children' => boolean false 3 => array (size=9) 'mid' => int 11 'pid' => int 0 'ord' => int 0 'title' => string '文章管理' (length=12) 'controller' => string '' (length=0) 'method' => string '' (length=0) 'ishidden' => int 0 'status' => int 0 'children' => array (size=1) 0 => array (size=8) 'mid' => int 16 'pid' => int 11 'ord' => int 0 'title' => string '文章列表' (length=12) 'controller' => string 'Article' (length=7) 'method' => string 'index' (length=5) 'ishidden' => int 0 'status' => int 0
Ini adalah kandungan yang dipaparkan seperti biasa
Mari kita lihat jika kita mempunyai data ini dahulu
seperti berikut
Versi Cina
Saya mendapati ralat. $menu dalam kaedah tambah hendaklah ditukar kepada $results
Salah $this->assign('menu',$menus);
Correct $this->assign('menu ' ,$hasil);
Ini adalah kandungan yang dipaparkan seperti biasa
Mari kita lihat jika kita mempunyai data ini dahulu
seperti berikut