auto_load_func('Application/Common/Server/'); //自动导入Server $common->auto_load_func('Application/Common/Common/util/'); //自动导入工具类(自己写的) $this->site_url = SITE_URL; $admin = self::get_my_info(); //自动运行,为了判断左侧导航、右侧导航的选中状态,S为导航ID cookie('s',I('s'),86400); //session不存在时,不允许直接访问 if(!$admin['aid']){ $this->error('还没有登录,正在跳转到登录页',U('Admin/Login/login')); } //session存在时,不需要验证的权限 $not_check = array('Index/index','Index/panel','Login/login','Common/base64_upload','Common/file_upload','Common/img_upyun','Common/upload_upyun'); //当前操作的请求 模块名/方法名 if(in_array(CONTROLLER_NAME.'/'.ACTION_NAME, $not_check)){ return true; } //下面代码动态判断权限 $auth = new Auth(); if(!$auth->check(CONTROLLER_NAME.'/'.ACTION_NAME,$admin['aid'])){ $this->error('没有权限'); } } /** * get封装 * @param type $get * $defalut默认值 默认null */ public function myGet($get, $defalut = null) { $result = $_GET[$get]; !empty($result) ? ($result = $result) : ($result = $defalut); $result = htmlspecialchars($result); return $result; } /** * post封装 * @param type $post */ public function myPost($post, $defalut = null) { $result = $_POST[$post]; !empty($result) ? ($result = $result) : ($result = $defalut); $result = htmlspecialchars($result); return $result; } /** * $request封装 * @param type $request * @param type $default * @return type */ public function myRequest($request, $defalut = null) { $result = $_REQUEST[$request]; !empty($result) ? ($result = $result) : ($result = $defalut); $result = htmlspecialchars($result); return $result; } //空操作 public function _empty() { header("HTTP/1.0 404 Not Found"); $this->assign('info', 'baseAction/_empty'); $this->display('./Tpl/404.html'); exit; } /** * 自动加载函数库 .php文件 * @param string $path 文件夹 */ public function auto_load_func($path) { $auto_funcs = glob($path . "*.php"); if (!empty($auto_funcs)) { foreach ($auto_funcs as $fileName) { include_once $fileName; } } } /** * 返回并重载上一页 * Transient_1988 */ public function goBack() { echo ''; exit; } /** * 保存登录信息 * @param array $info * @param int $time */ static public function set_my_info($info) { session('admin_motion', $info); } /** * 获取保存的登录信息 */ static public function get_my_info(){ return session('admin_motion'); } /** * 清除登录信息 */ static public function del_my_info(){ session('admin_motion', null); } /** * 获取面包屑 * @return array */ static function get_bread_crumbs(){ $name = CONTROLLER_NAME . '/' . ACTION_NAME ; $where = array('name' => $name); $field = 'id,name,title,pid'; $model = M('auth_rule'); $data = array(); $temp = $model->where($where)->field($field)->find(); while(!empty($temp)){ $data[] = $temp; $where = array('id' => $temp['pid']); $temp = $model->where($where)->field($field)->find(); } $data = array_reverse($data); return $data; } } ?>