web开发中rbac的示例分析
这篇文章主要为大家展示了"web开发中rbac的示例分析",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"web开发中rbac的示例分析"这篇文章吧。
//登陆控制器
functionactionLogin(){
$name=Yii::$app->request->post("name");
$pass=Yii::$app->request->post("pass");
$res=Yii::$app->db->createCommand("select*fromuserwherename='$name'andpass='$pass'")->queryOne();
if($res){
$session=Yii::$app->session;
$session->set("uid",$res['id']);
$id=$res['id'];
$sql=Yii::$app->db->createCommand("SELECT*fromuserjoinu_ton`user`.id=u_t.u_idjointeacheronu_t.t_id=teacher.idJOINt_ponteacher.id=t_p.t_idjoinpoweront_p.p_id=power.idwhere`user`.id=$id")->queryAll();
$session->set("power",json_encode($sql));
return$this->redirect(["one/show"]);
}else{
echo"
}
}
//权限控制器
functioninit()
{
$session=Yii::$app->session;
$id=$session->get("uid");
if(empty($id)){
echo"
}
$power=$session->get("power");
$power=json_decode($power);
foreach($poweras$k=>$v){
$arr[]=$v->controller.'/'.$v->function;
}
$res=Yii::$app->requestedRoute;
if(!in_array($res,$arr)){
echo"
}
}
functionactionShow(){
$session=Yii::$app->session;
$data=$session->get("power");
$arr=json_decode($data,1);
$res=$this->gettree($arr,0);
return$this->render("show",["res"=>$res]);
}
functiongettree($data,$pid){
$tree=[];
foreach($dataas$k=>$v){
if($v['pid']==$pid){
$v['son']=$this->gettree($data,$v['id']);
$tree[]=$v;
}
}
return$tree;
}
//权限展示
content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">