从此不求人:自主研发一套PHP前端开发框架(32)

插件化后台

index.inc(Controller目录下面的)

<?php class index extends _Master{ /** *permission{"role":"admin"} */ function adminindex(){ $this->_isadmin = true; $this->setView('index'); } function showindex(){ $this->setVar('title','测试一下大家的灵活性!'); $this->setView('index'); if(is_login()){ $this->setVar('username',the_user()->user_name); } } } ?>

主目录下面的index.php

<?php include('lkphp.conf'); //获取Controller参数 $_controller = isset($_GET['controller'])?$_GET['controller']:''; //获取action $_action = isset($_GET['action'])?$_GET['action']:''; //如果传入的controller 为空或者在定义的自定义列表里面那么就终止程序向下执行 if($_controller === ''|| in_array($_controller,explode(',',LKPHP_FORBIDDEN_TYPE))) exit(); error_reporting(E_ALL);//设定报错级别默认最高用于开发环境好调试错误 $current_role=array("admin","guest"); require(LKPHP_PATH.'Common/functions.inc');//加载公共函数库 require(LKPHP_PATH.'MVC/Controller/_Master.inc');//加载Controller父类 $_control_path = LKPHP_PATH.'MVC/Controller/'.$_controller.'.inc';//获取控制器类绝对地址 if(!file_exists($_control_path)){ exit();//判断是否存在此控制器类文件 } require($_control_path); if (!class_exists($_controller)) { exit();//判断是否存在此类 } $_init_controller = new $_controller(); if (method_exists($_init_controller, $_action)) { //在这里的话我们要进行角色判断 $getClass = new ReflectionClass($_controller); $getMethod = $getClass->getMethod($_action); if($getMethod){ $doc = $getMethod->getDocComment();//这个是可以获取php之中的注释的 if(preg_match("/permission\{(.*?)\}/i", $doc,$match)){ $permission = $match[1]; $permission = json_decode('{'.$permission.'}'); if(!in_array($permission->role,$current_role)){ exit('对不起您的权限不够,无法进行此操作!'); } } $_init_controller->$_action(); $_init_controller->run(); } } ?>

你可能感兴趣的:(从此不求人:自主研发一套PHP前端开发框架(32))