サマリー:<?php /** * 基礎類,驗證是否登錄 */ namespace app\admins\controller; use think\App; use think\Controller; use think\Db; use think\facade\Request; use think\fac
<?php /** * 基礎類,驗證是否登錄 */ namespace app\admins\controller; use think\App; use think\Controller; use think\Db; use think\facade\Request; use think\facade\Session; class Base extends Controller { public function __construct() { parent::__construct(); if(!Session::has('admin')){ header('Location:/index.php/admins/Login/login'); /*$this->error('您還未登陸,請返回登陸!','Login/login');*/ exit(); } $this->admin = Session::get('admin'); $this->assign('admin',$this->admin['username']); //判斷用戶是否有權限 $group = Db::table('roles')->where(array('gid'=>$this->admin['gid']))->find(); if(!$group){//這里要判斷是ajax提交的數(shù)據(jù)還是路由訪問的,二者要返回不一樣的數(shù)據(jù)格式 $this->request_error('對不起,您沒有訪問權限'); } $rights = json_decode($group['rights']); //通過訪問的方法來判斷這些控制器或方法是否存在 $controller = Request::controller(); $method = Request::action(); $res = Db::table('admins_menu')->where(array('controller'=>$controller,'method'=>$method))->find(); if(!$res){ $this->request_error('對不起,您訪問的功能不存在'); } if($res['status']==1){ $this->request_error('對不起,該功能已禁用'); } if(!in_array($res['mid'],$rights)){ $this->request_error('對不起,您沒有權限'); } } private function request_error($msg) { if(Request::isAjax()){//如果是ajax提交 exit(json_encode(array('code'=>1,'msg'=>$msg))); } exit($msg); } }
添削の先生:查無此人添削時間:2019-04-18 09:46:53
先生のまとめ:完成的不錯??蚣艽罱ê茫髮戫椖烤秃芊奖懔?。繼續(xù)加油。