1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\base\controller;
- use think\Controller;
- use think\Request;
- use think\Auth;
- /**
- * 创建控制器基类
- * @author Superbee
- *
- */
- class Base extends Controller{
-
- public function _initialize(){
- parent::_initialize();
-
- $this->assign("rootpath", $this->request->root());
-
- $this->check_login();
- $this->check_auth();
- }
-
- /**
- * 检测是否登录
- */
- private function check_login(){
- $admin = session('admin');
-
- if(empty($admin)){
- $this->redirect($this->request->root().'/base/login/login');
- }
-
- }
-
- /**
- * 检查权限
- */
- private function check_auth(){
- $m = $this->request->module ();
- $c = $this->request->controller ();
- $a = $this->request->action ();
- $rule_name = '/'.$m.'/'.$c.'/'.$a;
-
- $auth = new Auth();
- $id = session('admin')['id'];
- $result = $auth->check($rule_name, $id);
- // if(!$result){
- // $this->error('您没有权限访问');
- // }
- }
-
- }
|