Home > php教程 > php手册 > 最高效的无限级菜单生成方法

最高效的无限级菜单生成方法

WBOY
Release: 2016-06-07 11:42:33
Original
1546 people have browsed it

最高效的无限级菜单生成方法
$Menu= M('Menu');<br> $items= $Menu->order('pid, sort')->select();//按pid从小到大排序,以保证父节点在前,子节点在后。sort是同一层次节点的显示顺序。<br> $menu = array();<br> foreach ($items as $v) {<br>     $menu[$v['_id']] = $v;<br>     $menu[$v['_id']]['items'] = array();//items存放当前节点的所有子节点。<br>     if($v['pid'] != 0) {<br>         $menu[$v['pid']]['items'][$v['_id']] = &$menu[$v['_id']];<br>     }<br> }<br> foreach ($menu as $k=>$v) {<br>     if($v['pid'] != 0) {<br>         unset($menu[$k]);<br>     }<br> }OT里面有对该功能的封装,目录位置Application\Common\Common\function.php文件里的list_to_tree函数,function.php文件里面还有很多功能函数大家可以看看。

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template