国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

ThinkPHP RBAC如何自動獲取所有模塊的函數

2020-03-22 18:16:15
字體:
來源:轉載
供稿:網友
  • 之前我寫過一個例子,關于ThinkPHP RBAC權限控制的,后來又研究了下,發現在真實的情況中,很多crm,cms等,有需要去獲取RBAC所有模塊,然后進行權限分配等操作,或者增加刪除模塊。
    所以就想了一個思路去實現自動獲取ThinkPHP所有的模塊
    大致思路是:
    1、根據配置文件獲取分組
    2、遍歷分組下的Action文件夾中的*Action.html' target='_blank'>class.php
    3、實例化Action,獲取其所有方法,過濾掉tp本身的底層函數
    4、小手一揮,數據到手.
    以下就是具體的代碼,其實思路更加重要,我也不能確定我的就是最好的。我也不可能去一行一行的講解。大家自己有時間可以研究一下。

    //生成模塊結構信息 app/分組/模塊/方法    public function fetch_module(){        $M = M('Module');        $M->query("truncate table module");        $app = $this->getAppName();        $groups = $this->getGroup();        $n=0;        foreach ($groups as $group) {            $modules = $this->getModule($group);            foreach ($modules as $module) {                $module_name=$app.'://'.$group.'/'.$module;                $functions = $this->getFunction($module_name);                foreach ($functions as $function) {                    $data[$n]['app'] = $app;                    $data[$n]['group'] = $group;                    $data[$n]['module'] = $module;                    $data[$n]['function'] = $function;                    ++$n;                                }            }        }        $M->addAll($data);        $this->success('所有分組/模塊/方法已成功讀取到module表中.');    }    protected function getAppName(){        return APP_NAME;    }    protected function getGroup(){        $result = explode(',',C('APP_GROUP_LIST'));        return $result;    }    protected function getModule($group){        if(empty($group))return null;        $group_path=LIB_PATH.'Action/'.$group;        if(!is_dir($group_path))return null;        $group_path.='/*.class.php';        $ary_files = glob($group_path);        foreach ($ary_files as $file) {            if (is_dir($file)) {                continue;            }else {                    $files[] = basename($file,'Action.class.php');            }        }        return $files;    }    protected function getFunction($module){        if(empty($module))return null;        $action=A($module);        $functions=get_class_methods($action);        $inherents_functions = array(            '_initialize','__construct','getActionName','isAjax','display','show','fetch',            'buildHtml','assign','__set','get','__get','__isset',            '__call','error','success','ajaxReturn','redirect','__destruct'        );        foreach ($functions as $func){            if(!in_array($func, $inherents_functions)){                $customer_functions[]=$func;            }        }        return $customer_functions;    }

    Model表的結構

    CREATE TABLE `module` (  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  `name` varchar(45) DEFAULT NULL COMMENT '名稱',  `app` varchar(45) DEFAULT NULL COMMENT '項目',  `group` varchar(45) DEFAULT NULL COMMENT '分組',  `module` varchar(45) DEFAULT NULL COMMENT '模塊',  `function` varchar(45) DEFAULT NULL COMMENT '方法',  `status` varchar(45) DEFAULT NULL COMMENT '狀態',  PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8$$

    PHP編程

    鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 寿光市| 阳东县| 永昌县| 墨玉县| 卢龙县| 武强县| 南平市| 汝阳县| 会理县| 东乡| 育儿| 新营市| 教育| 通许县| 苗栗县| 两当县| 平顶山市| 横峰县| 白山市| 嘉荫县| 出国| 河津市| 老河口市| 繁昌县| 陆良县| 额敏县| 宜兴市| 屏山县| 武威市| 元江| 安龙县| 宁蒗| 萨迦县| 温宿县| 长葛市| 香港| 固始县| 山阴县| 文昌市| 茶陵县| 蚌埠市|