公共控制器
/**
* 公共初始化
* &#64;Author 闻子 <270988107&#64;qq.com>
* &#64;Return \think\response\View|void
*/
public function initialize()
{
$this->NavBarlist();
}
/**
* 后台侧边栏
* &#64;Author 闻子 <270988107&#64;qq.com>
*/
private function NavBarlist()
{
$modulesList &#61; getModulesCatalog(Env::get(&#39;app_path&#39;));
$labels &#61; [];
$jsonData &#61; [];
foreach ($modulesList as $k&#61;>$v) {
$modulesUrl &#61; Env::get(&#39;app_path&#39;) . $v . &#39;\info.json&#39;;
$jsonData[] &#61; json_decode(file_get_contents($modulesUrl),true);
}
foreach ($jsonData as $key &#61;> $value) {
if (!empty($value[&#39;admin_menu&#39;])) {
$labels[] &#61; $jsonData[$key][&#39;admin_menu&#39;];
}
}
foreach ($labels as $key &#61;> $item) {
foreach($item as $k &#61;> $v){
$arr[] &#61; $v;
}
}
$this->assign(&#39;NavBarlist&#39;,$arr);
}
公共文件common
/**
* 获取模块目录
* &#64;Author 闻子 <270988107&#64;qq.com>
* &#64;Param $dir
* &#64;Return array
*/
function getModulesCatalog($dir)
{
$dirArray[] &#61; NULL;
if (false !&#61; ($handle &#61; opendir($dir))) {
$i &#61; 0;
while (false !&#61;&#61; ($file &#61; readdir($handle))) {
if ($file !&#61; "." && $file !&#61; ".." && $file !&#61; ".htaccess" && $file !&#61; "common" && !strpos($file, ".")) {
$dirArray[$i] &#61; $file;
$i&#43;&#43;;
}
}
closedir($handle);
}
return $dirArray;
}
json文件
{
"name": "admin",
"title": "后台",
"description": "一款基础后台模块",
"author": "Wz",
"version": "1.0.0",
"is_module": 1,
"is_admin": 1,
"admin_menu": [
{
"title": "仪表盘",
"url": "admin/index/index",
"icon": "layui-icon-dashboard",
"is_status": 1
},
{
"title": "模块管理",
"url": "",
"icon": "layui-icon-dashboard",
"is_status": 1,
"menu_list": [
{
"title": "模块列表",
"url": "admin/modules/index",
"is_status": 1
}
]
}
],
"database_prefix": "wz_"
}