<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
class Base extends Controller
{
//
public function __construct(Request $request = null)
{
//判断用户是否登录
if (!session('?admin_id')){
$this->error('请先登录','/admin/login/login');
}
//判断是否拥有权限
//先获取当前访问的控制器和方法
$controller = \request()->controller();
$action = \request()->action();
//当前访问的路径
$currentPath = strtolower($controller).'/'.strtolower($action);
$nodePath = ['index/index','index/welcome'];
//查询当前的权限
$userNode = session('userNode');
foreach ($userNode as $k=>$v){
foreach ($v['child'] as $item){
$nodePath[] = $item['controller'].'/'.$item['action'];
}
}
//判断是否有权限访问
if (!in_array($currentPath,$nodePath)){
$this->error('暂无权限访问','/admin/index/index');
}
parent::__construct($request);
}
}