标签:data == 限时 option 无限 value function style volist
无限级分类,在做权限时可以将层级展现出来,
public function privilege(){ $data = Db::table(‘privilege‘)->select(); return $this->tree($data,$parent_id=0,$level=0); } public function tree($arr,$parent_id,$level){ static $tree=[]; foreach($arr as $key =>$v){ if($v[‘parent_id‘] == $parent_id){ $tree[]=[ ‘privilege_id‘=>$v[‘privilege_id‘], ‘privilege_name‘=>$v[‘privilege_name‘], ‘level‘ => $level, ‘parent_id‘=>$parent_id ]; $this->tree($arr,$v[‘privilege_id‘],$level+1); } } return view("privilege_add",[‘arr‘=>$tree]); }
添加时的代码
<tr> <td class="label">父级菜单</td> <td> <select name="parent_id" > <option value="0">顶级权限</option> {volist name="arr" id="vo"} <option value="{$vo.privilege_id}"> <a href="">{php} echo str_repeat(‘  ‘,$vo[‘level‘]*2){/php}{$vo.privilege_name}</a> </option> {/volist} </select> </td> </tr>
标签:data == 限时 option 无限 value function style volist
原文地址:https://www.cnblogs.com/yingyong/p/9935036.html