thinkphp frame Onethink Background support level three menu

Source: Internet
Author: User
Tags foreach

Onethink Background Support level three menu, CMS Admin 1.0 version itself does not support the three level menu, a little change, you can support the Unlimited class classification


/**
* Get the Controller menu array, the level two menu element is located in the ' _child ' element of the first level menu
* @author Zhuyaje <xcoolcc@gmail.com>
*/
Final public Function Getmenus ($controller =controller_name) {
$menus = Session (' Admin_menu_list '. $controller);

$flag =false;//to open menu level three menus

if (empty ($menus)) {
Get main Menu
$where [' pid '] = 0;
$where [' hide '] = 0;
if (! C (' Develop_mode ')) {//whether developer mode
$where [' is_dev '] = 0;
}
$menus [' main '] = M (' Menu ')->where ($where)->order (' sort ASC ')->select ();

$menus [' child '] = array (); Set child nodes

Highlight Main Menu
$current = M (' menu ')->where ("url like '%{$controller}/.") Action_name. " % ' ")->field (' id ')->find ();
if ($current) {
$nav = D (' Menu ')->getpath ($current [' id ']);
$nav _first_title = $nav [0][' title];

foreach ($menus [' main '] as $key => $item) {
if (!is_array ($item) | | empty ($item [' title ']) | | empty ($item [' URL '])] {
$this->error (' Controller base class $menus attribute element configured incorrectly ');
}
if (Stripos ($item [' url '],module_name)!==0) {
$item [' url '] = module_name. ' /'. $item [' url '];
}
To determine the main menu permissions
if (!is_root &&! $this->checkrule ($item [' URL '],authrulemodel::rule_main,null)] {
unset ($menus [' main '] [$key]);
continue;//Continue Cycling
}

Gets the submenu item for the current main menu
if ($item [' title '] = = $nav _first_title) {
$menus [' main '] [$key] [' class ']= ' current ';
Generate Child tree
$groups = M (' menu ')->where ("pid = {$item [' id ']}")->distinct (True)->field ("' Group '")->select ();
if ($groups) {
$groups = Array_column ($groups, ' group ');
}else{
$groups = Array ();
}

Get the legal URL of level two classification
$where = Array ();
$where [' pid '] = $item [' id '];
$where [' hide '] = 0;
if (! C (' Develop_mode ')) {//whether developer mode
$where [' is_dev '] = 0;
}
$second _urls = M (' Menu ')->where ($where)->getfield (' Id,url ');
$third _urlss=array ();

if (!empty ($second _urls) && $flag) {
foreach ($second _urls as $key => $v) {

$wheres = Array ();
$wheres [' pid '] = $key;
$wheres [' hide '] = 0;
if (! C (' Develop_mode ')) {//whether developer mode
$wheres [' is_dev '] = 0;
}
$third _urls[] = M (' Menu ')->where ($wheres)->getfield (' Id,url ');
foreach ($third _urls as $VV) {
foreach ($vv as $key => $vs) {
$third _urlss[$key]= $vs;
}
}
}
}

if (!is_root) {
Detect Menu Permissions
$to _check_urls = Array ();

foreach ($second _urls as $key => $to _check_url) {
if (Stripos ($to _check_url,module_name)!==0) {
$rule = module_name. ' /'. $to _check_url;
}else{
$rule = $to _check_url;
}
if ($this->checkrule ($rule, Authrulemodel::rule_url,null))
$to _check_urls[] = $to _check_url;
}
if (!empty ($third _urlss) && $flag) {
foreach ($third _urlss as $key => $to _check_urlss) {
if (Stripos ($to _check_urlss,module_name)!==0) {
$rules = module_name. ' /'. $to _check_urlss;
}else{
$rules = $to _check_urlss;
}
if ($this->checkrule ($rules, Authrulemodel::rule_url,null))

echo $rules. " <br/> ";
$to _check_urlsss[] = $to _CHECK_URLSS;
}
}

}

To generate a submenu tree by grouping
foreach ($groups as $g) {
$map = Array (' group ' => $g);
if (Isset ($to _check_urls)) {
if (Empty ($to _check_urls)) {
Does not have any permissions
Continue
}else{
$map [' url '] = Array (' In ', $to _check_urls);
}
}
$map [' pid '] = $item [' id '];
$map [' hide '] = 0;
if (! C (' Develop_mode ')) {//whether developer mode
$map [' is_dev '] = 0;
}
$menuList = M (' Menu ')->where ($map)->field (' Id,pid,title,url,tip ')->order (' sort ASC ')->select ();

$menus [' Child '] [$g] = List_to_tree ($menuList, ' id ', ' pid ', ' Operater ', $item [' id ']);
Support Level Three Menu
if (!empty ($menus [' Child '] [$g]) && $flag) {
foreach ($menuList as $key => $v) {
$maps [' pid '] = $v [' id '];
$menuLists = M (' Menu ')->where ($maps)->field (' Id,pid,title,url,tip ')->order (' sort ASC ')->select ();
$menus [' Child '] [$g] [$key] [' ttt '] = List_to_tree ($menuLists, ' id ', ' pid ', ' Operater ', $v [' id ']);
}
}
}
if ($menus [' child '] = = Array ()) {
$this->error (' main menu is missing submenu, please go to system = ' background menu management Add ');
}
}
}
}
Session (' Admin_menu_list '. $controller, $menus);
}
return $menus;
}

Then public/base.html

<!--sidebar-->
<div class= "sidebar" >
<!--Sub-navigation-->
<block name= "sidebar" >
<div class= "Sidebar-collapse" id= "Sidebar-collapse" >
<i class= "FA fa-angle-double-left" ><<</i>
</div>
<div id= "Subnav" class= "Subnav" >
<notempty name= "_extra_menu" >
{//Dynamic Extended menu//}
{: Extra_menu ($_extra_menu,$__menu__)}
</notempty>
<volist name= "__menu__.child" id= "Sub_menu" >
<!--Sub-navigation-->
<notempty name= "Sub_menu" >
<notempty name= "key" ><ul class= "Side-sub-menu" >
<volist name= "Sub_menu" id= "Menu" >
<li>
<a class= "Item" href= "{$menu. url| U} ">{$menu .title}</a>
</li>
</volist>
<notempty name= "MENU.TTT" >
<volist name= "menu.ttt" id= "Menus" >
<li>
<a class= "Item" href= "{$menus. url| U} ">{$menus .title}</a>
</li>
</volist>
</notempty>
</ul>
</notempty>
<!--/Sub-navigation-->
</volist>
</div>
</block>
<!--/Sub-navigation-->
</div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.