gpt4 book ai didi

php - 动态菜单权限不起作用

转载 作者:行者123 更新时间:2023-11-29 21:10:16 25 4
gpt4 key购买 nike

这是我的代码

<ul class="nav side-menu">


<?php
$mnquery=$ob->showDataall("select * from menus where parent_id='0' and delet='0'");
foreach($mnquery as $value)
{
$selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
foreach($selquery as $nquery)
{
foreach(explode(",",$nquery['permission']) as $mnu)
{
if($value['menu_id']==$mnu)
{
?>
<li><a <?php if($value['menu_hyper']!='#'){ echo 'href="'.$value['menu_hyper'].'"';}?>><i class="fa fa-bars"></i><?php echo $value['menu_name']; if($value['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>
<?php
$submnquery=$ob->showDataall("select * from menus where parent_id='".$mnu."' and delet='0'");
if(!empty($submnquery))
foreach($submnquery as $subvalue)
{
if($subvalue['parent_id']==$mnu)
{
?>
<ul class="nav child_menu" style="display: none">
<li><a <?php if($subvalue['menu_hyper']!='#'){ echo 'href="'.$subvalue['menu_hyper'].'"';}?>><?php echo $subvalue['menu_name']; if($subvalue['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>
<?php
$chldmnquery=$ob->showDataall("select * from menus where parent_id='".$subvalue['menu_id']."' and delet='0'");
if(!empty($chldmnquery))
foreach($chldmnquery as $chldvalue)
{
if($chldvalue['parent_id']==$subvalue['menu_id'])
{
?>
<ul class="nav child_menu" style="display: none">
<li><a href="<?php echo $chldvalue['menu_hyper'];?>"><?php echo $chldvalue['menu_name'];?></a></li>
</ul>
<?php
}
}
?>

</li>
</ul>
<?php
}
}
?>
</li>
<?php
}
}
}
}
?>
</ul>

这是我的函数 showDataall

public function showDataall($result) 
{
$q = $this->conn->prepare($result) or die("failed!");
$q->execute();
while ($r = $q->fetch(PDO::FETCH_ASSOC))
{
$data[] = $r;
}
return $data;
}

这是我的表格,名为“菜单

     menu_id       menu_name            menu_hyper                 parent_id    delet
1 Master Settings # 0 0
2 Add New Menu ../pages/menu_add.php 1 0
3 Menu Permission ../pages/menu_permissions.php 1 0
4 Role ../pages/add_role.php 1 0
5 Staff ../pages/add_staff.php 1 0
6 Add Product ../pages/product_add.php 0 0

这是我的其他表,名为“menu_permission

  id    staff_id    permission
1 1 1,2,3,4,5,6
2 2 1,4

我允许“staff_id=1”的所有菜单权限
我允许“staff_id=2”使用 menu_id 14
staff_id=1 记录在所有显示的菜单中,但 staff_id=2 记录在所有显示的菜单中
我只允许 Staff_id=2 有两个菜单 (menu_id = 1且menu_id = 2)如何解决这个问题

请帮助我......

最佳答案

我写的是我的知识......它的工作完美
任何人都可以帮助我简化这段代码

              <?php 
$mnquery=$ob->showDataall("select * from menus where parent_id='0' and delet='0'");
foreach($mnquery as $value)
{
$selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
foreach($selquery as $nquery)
{
foreach(explode(",",$nquery['permission']) as $mnu)
{
if($value['menu_id']==$mnu)
{
?>
<li><a <?php if($value['menu_hyper']!='#'){ echo 'href="'.$value['menu_hyper'].'"';}?>><i class="fa fa-bars"></i><?php echo $value['menu_name']; if($value['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>
<?php
$submnquery=$ob->showDataall("select * from menus where parent_id='".$mnu."' and parent_id!='0' and delet='0'");
if(!empty($submnquery))
foreach($submnquery as $subvalue)
{
$selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
foreach($selquery as $nquery)
{
foreach(explode(",",$nquery['permission']) as $mnua)
{
if($subvalue['menu_id']==$mnua)
{
?>
<ul class="nav child_menu" style="display: none">
<li><a <?php if($subvalue['menu_hyper']!='#'){ echo 'href="'.$subvalue['menu_hyper'].'"';}?>><?php echo $subvalue['menu_name']; if($subvalue['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>





<?php
$chldmnquery=$ob->showDataall("select * from menus where parent_id='".$subvalue['menu_id']."' and delet='0'");
if(!empty($chldmnquery))
foreach($chldmnquery as $chldvalue)
{
$selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
foreach($selquery as $nquery)
{
foreach(explode(",",$nquery['permission']) as $mnub)
{
if($chldvalue['menu_id']==$mnub)
{
?>
<ul class="nav child_menu" style="display: none">
<li><a href="<?php echo $chldvalue['menu_hyper'];?>"><?php echo $chldvalue['menu_name'];?></a></li>
</ul>
<?php
}
}
}
}
?>

</li>
</ul>
<?php
}
}
}
}
?>
</li>
<?php
}
}
}
}
?>
</ul>

关于php - 动态菜单权限不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36443954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com