導(dǎo)入菜單
在安裝插件時,webman-admin會自動導(dǎo)入plugin/插件/config/menu.php
配置里的菜單,卸載插件時也會根據(jù)此配置刪除菜單。
menu.php 內(nèi)容類似如下
<?php
use plugin\queue\app\controller\redis\DelayController;
use plugin\queue\app\controller\redis\FailedController;
use plugin\queue\app\controller\redis\NormalController;
return [
[
'title' => '消息隊列',
'key' => 'queue',
'icon' => 'layui-icon-align-left',
'weight' => 0,
'type' => 0,
'children' => [
[
'title' => '正常隊列',
'key' => NormalController::class,
'href' => '/app/queue/redis/normal',
'type' => 1,
'weight' => 0,
],
[
'title' => '延遲隊列',
'key' => DelayController::class,
'href' => '/app/queue/redis/delay',
'type' => 1,
'weight' => 0,
],
[
'title' => '失敗隊列',
'key' => FailedController::class,
'href' => '/app/queue/redis/failed',
'type' => 1,
'weight' => 0,
]
]
]
];
字段說明
各字段說明如下
title
菜單名稱
type
類型,0為目錄,1為菜單,2為權(quán)限節(jié)點(權(quán)限節(jié)點會自動生成,一般不用配置)
key
菜單標(biāo)識,要求全局唯一。
- 一級目錄要求格式為
插件名
- 二級及以上目錄要求格式為
插件名-任意字符串
- 如果是菜單,則填寫控制器類的名稱(帶命名空間)
href
url路徑,一般填寫控制器對應(yīng)的url路徑
icon
顯示圖標(biāo),只有一級目錄或者頂級菜單才會顯示圖標(biāo)。目前只支持layui圖標(biāo),可選值參考layui圖標(biāo)
weight
權(quán)重,用來排序,值大的在前,值小的在后
測試安裝
如果你的應(yīng)用插件是使用 php webman app-plugin:create
命令生成的,則會生成一個plugin/插件名/api/Install.php
類,類里面install方法用于安裝菜單,uninstall方法用于卸載菜單。我們可以通過以下命令來測試install以及uninstall方法。
安裝菜單
php webman app-plugin:install 插件名
卸載菜單
php webman app-plugin:uninstall 插件名
提示
如果你的應(yīng)用插件需要在安裝或者卸載時觸發(fā)某個操作,可以寫在Install
類里的install
或uninstall
方法中