可以在【Common/Controller下||模块/Controller】建一个类
类名可以是AuthController.class.php 或 CommonController.class.php(whatever)
namespace Common\Controller; use Think\Controller; use Think\Auth; class AuthController extends Controller{ public function _initialize(){ $auth=new Auth(); if (CONTROLLER_NAME.‘/‘ . ACTION_NAME == "Index/index") { if (!$auth->check(CONTROLLER_NAME.‘/‘ . ACTION_NAME, session(‘aid‘))) { $this->error("请先登录", U("Login/login")); } } else { if (!$auth->check(CONTROLLER_NAME.‘/‘ . ACTION_NAME, session(‘aid‘))) { if(empty($_SESSION[‘aid‘])) { echo "<script>"; echo "alert(‘登录已过期,请重新登录!‘);"; echo "</script>"; exit(); } echo "<script>"; echo "alert(‘你没有操作权限!‘);"; echo "</script>"; echo "<h1>你没有操作权限!</h1>"; exit(); } } } }
需要权限管理的类继承控制类就可以了
class IndexController extends AuthController {
本文出自 “从头越” 博客,转载请与作者联系!
原文地址:http://minabo.blog.51cto.com/10888635/1748464