84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
Wie folgt
中文版
找到错误了,add方法里这个$menus要改成$results
错误的 $this->assign('menus',$menus);
正确的 $this->assign('menus',$results);
<?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
这是正常显示的内容
先看看有没有这些数据
如下
中文版
找到错误了,add方法里这个$menus要改成$results
错误的 $this->assign('menus',$menus);
正确的 $this->assign('menus',$results);
这是正常显示的内容
先看看有没有这些数据
如下