插件菜单
我们已经为您编写好了,导出用户菜单的函数,如果您的插件编写完毕后,点击打包按钮即可,默认的菜单路径应该是在/plugin/worker/data/menu.php
您可以把一些静态文件,例如.dat .db等文件,放在data文件方便统一管理、如果您需要自己DIY菜单,请修改menu.php文件即可,
如果当前menu.php
不存在,则不会写入菜单!!
前后端菜单
如果我们需要创建多级菜单,我们的 $menu
值应该是这样
<?php
return [
0 => [
'title' => '开发助手',
'router' => '/developer',
'icon' => 'fa-plug',
'auth' => 1,
'type' => 0,
'children' => [
0 => [
'title' => '插件开发',
'router' => '/developer/Plugin/index',
'icon' => '',
'auth' => 1,
'type' => 0,
],
1 => [
'title' => '代码生成',
'router' => '/developer/Generate/index',
'icon' => '',
'auth' => 1,
'type' => 0,
],
],
],
1 => [
'title' => '开发示例',
'router' => '/developer/Example/',
'icon' => 'fa-gitlab',
'auth' => 1,
'type' => 0,
'children' => [
0 => [
'title' => '基础表单',
'router' => '/developer/Example/index',
'icon' => '',
'auth' => 1,
'type' => 0,
],
1 => [
'title' => '数据表格',
'router' => '/developer/Example/table',
'icon' => '',
'auth' => 1,
'type' => 0,
],
2 => [
'title' => '卡片列表',
'router' => '/developer/Example/card',
'icon' => '',
'auth' => 1,
'type' => 0,
],
3 => [
'title' => '统计图表',
'router' => '/developer/Example/echarts',
'icon' => '',
'auth' => 1,
'type' => 0,
],
4 => [
'title' => '组件示例',
'router' => '/developer/Example/component',
'icon' => '',
'auth' => 1,
'type' => 0,
],
5 => [
'title' => '文本编辑器',
'router' => '/developer/Example/editor',
'icon' => '',
'auth' => 1,
'type' => 0,
],
6 => [
'title' => '常规辅助元素',
'router' => '/developer/Example/auxiliar',
'icon' => '',
'auth' => 1,
'type' => 0,
],
],
],
];
其中 children
表示下级菜单的配置,但建议菜单级数不宜过多,合理的栏目规划能更方便后台的使用。
提示:后台菜单项请注意大小写/驼峰法的方式去访问和调用,否则在Linux环境下会出现找不到控制器!
后台菜单操作
有时候我们需要临时禁用/关闭当前插件,只需要在后端点击关闭即可,如果我们有一些其他的逻辑需要编写,
那么请在插件的 Worker.php
对应的方法中添加上相应的操作。如
/**
* 插件启用方法
* @return bool
*/
public function enabled()
{
return true;
}
/**
* 插件禁用方法
* @return bool
*/
public function disabled()
{
return true;
}
会员中心菜单
如果我们开发的插件有前台会员中心菜单,我们可以通过使用get_plugin_menu
函数来获取用户插件前台菜单
if (!function_exists('get_plugin_menu')) {
/**
* 获取前台插件菜单
* @return void
*/
function get_plugin_menu()
{
$pluginNav = '';
$pluginList = get_plugin_list();
foreach ($pluginList as $item) {
try {
if (!$item['status']) {
continue;
}
$file = plugin_path($item['name']) . 'data/menu.html';
if (is_file($file)) {
$pluginNav .= file_get_contents($file) . PHP_EOL;
}
} catch (\Throwable $th) {
continue;
}
}
echo $pluginNav;
}
}
swiftadmin框架会员中心菜单 地址在 plugin/demo/data/menu.html
// 添加会员中心菜单
<li class="layui-nav-item">
<a class="#" lay-href="/worker.index/index">工单管理系统</a>
</li>
并且在 app/index/view/user/userNav.html
文件中做了如下调用
<!--// 初始化菜单-->
<ul class="layui-nav layui-nav-tree" lay-filter="master">
<li class="layui-nav-item layui-this">
<a lay-href="/user/profile">控制台</a>
</li>
<!--// 前台菜单-->
{:get_plugin_menu()}
<li class="layui-nav-item">
<a class="#" href="javascript:;">账号设置</a>
<dl class="layui-nav-child">
<dd><a lay-href="/user/security">安全设置</a></dd>
</dl>
</li>
</ul>
如何升级菜单
只要插件的menu.php文件存在,那么无论是在安装或者升级的时候,都会重复将这个文件数组通过查询的方式写入到数据库中。
如果你有其他的升级逻辑需要操作,比如删减数据库字段,改写字段类型,请在 Upgrade.php
方法体中编写你所需的代码逻辑、或者给安装脚本增加一些额外的SQL语句用于执行
/**
* 插件升级方法
* @return bool
*/
public function execute()
{
return true;
}
常见问题
暂无
最后更新时间:2022-08-22 10:51:01968 https://doc.swiftadmin.net/developer/54.html