您当前的位置: 首页 > 

暂无认证

  • 1浏览

    0关注

    95081博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

yii2中怎么输出二级菜单,根据我自己的样式建立的二级菜单

发布时间:2022-02-24 21:50:48 ,浏览量:1

sql:

CREATE TABLE `category` ( `id` int(50) NOT NULL, `name` varchar(50) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '分类名称', `pid` int(11) NOT NULL DEFAULT '0' COMMENT '父级分类id', `url` varchar(50) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '访问地址', `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', `created_at` int(12) NOT NULL COMMENT '创建时间', `updated_at` int(12) NOT NULL COMMENT '修改时间' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci; -- -- 转存表中的数据 `category` -- INSERT INTO `category` (`id`, `name`, `pid`, `url`, `status`, `created_at`, `updated_at`) VALUES (1, 'cyg', 0, 'www.baidu.com', 1, 1645603515, 1645603515), (2, 'liwen', 1, 'www.bauc.om', 1, 1645604857, 1645604857); 

helpers

 public static function getTree($list,$pid=0) { $tree=[]; foreach($list as $row) { if($row['pid']==$pid) { $tree[$row['id']]=$row; $children=self::getTree($list,$row['id']); $children&&$tree[$row['id']]['children']=$children; } } return $tree; } public static function getTrees($list,$pid=0,$level=0) { static $tree=[]; foreach ($list as $k => $row) { if($row['pid']==$pid) { $row['name']=html_entity_decode(str_repeat("  ",$level))."|--".$row['name']; $tree[$row['id']]=$row; unset($list[$k]); self::getTrees($list,$row['id'],$level+1); } } return $tree; } } 

在这里插入图片描述 后台数据:

            
关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.0905s