//登陆控制器 function actionlogin(){ $name=yii::$app->request->post("name"); $pass=yii::$app->request->post("pass"); $res= yii::$app->db->createcommand("lect * from ur where name='$name' and p提分ass='$pas沈从文边城s'")->queryone(); if ($res){ $ssion=yii::$app->ssion; $ssion->t("uid",$res['id']); $id=$res['id']; $sql=yii::$app->db->creat冬夜读书示子聿的诗意ecommand("lect * from ur join u_t on `ur`.id=u_t.u_id join teacher on u_t.t_id=teacher.id join t_p on teacher.id=t_p.t_id join power on t_p.p_i两小儿辩日原文d=power.id where `ur`.id=$id")->queryall(); $ssion->t("power",json_encode($sql)); return $this->redirect(["one/show"]); }el{ echo "<a href='add'>登陆失败</a>"; } }
//权限控制器 function init() { $ssion=yii::$app->ssion; $id=$ssion->get("uid"); if (empty($id)){ echo "<a href='/mon/add'>权限不足</a>"; } $power= $ssion->get("power"); $power= json_decode($power); foreach ($power as $k=>$v){ $arr[]=$v->controller.'/'.$v->function; } $res=yii::$app->requestedroute; if (!in_array($res,$arr)){ echo "<a href='/mon/add'>权限不足</a>";die; } } function actionshow(){ $ssion=yii::$app->ssion; $data=$ssion->get("power"); $arr=json_decode($data,1); $res= $this->gettree($arr,0); return $this->render("show",["res"=>$res]); } function gettree($data,$pid){ $tree=[]; foreach ($data as $k=>$v){ if ($v['pid']==$pid){ $v['son']=$this->gettree($data,$v['id']); $tree[]=$v; } } return $tree; }
//权限展示<!doctype html><html lang="en"><head> <meta chart="utf-8"> <meta name="viewport" content="width=device-width, ur-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>document</title></head><body> <table> <?php foreach ($res as $key=>$value){?> <tr> &发财梦lt;?php echo $value['power'] ?><br> <?php foreach ($value['son'] as $k=>$v){?> <a href="<?php echo $v['function'] ?>"><?php echo $v['power'] ?><br></a> </tr> <?php }?> <?php }?> </table></body></html>
本文发布于:2023-04-07 08:36:25,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/97418cd64614bb77e18c63a091adffdd.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:php 的 RBAC实现.doc
本文 PDF 下载地址:php 的 RBAC实现.pdf
留言与评论(共有 0 条评论) |