🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 3. 插件名称类 ## 插件名称类 与插件名称一致,其中首字母大写。例如Demo类对应demo标识。主要用于安装、卸载、禁用、启用、处理事件逻辑。该文件必须存在 ## 目录位置 ``` <pre class="calibre16">``` addons ├─demo │ ├─Demo<span class="token1">.</span>php <span class="token">-</span><span class="token">></span>与插件名称保持一致,其中首字母大写(该文件必须存在) │ ├─info<span class="token1">.</span>ini ``` ``` ## 文件代码示例 每个名称类,需要继承Addons类,里面有提供获取插件信息,配置文件,加载模板等方法。 ``` <pre class="calibre20">``` <span class="token"><</span><span class="token">?</span>php declare <span class="token1">(</span>strict_types<span class="token">=</span><span class="token3">1</span><span class="token1">)</span><span class="token1">;</span> <span class="token5">// 命名空间,addons文件夹,demo 你的插件文件夹</span> namespace addons\demo<span class="token1">;</span> use think\Addons<span class="token1">;</span> class <span class="token6">Demo</span> extends <span class="token6">Addons</span> <span class="token1">{</span> <span class="token5">// 插件安装时的处理(必须存在该方法)</span> public <span class="token2">function</span> <span class="token6">install</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token3">true</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">// 插件卸载时的处理(必须存在该方法)</span> public <span class="token2">function</span> <span class="token6">uninstall</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token3">true</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">// 插件启用时触发(可选)</span> public <span class="token2">function</span> <span class="token6">enable</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token3">true</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">// 插件禁用时的处理(可选)</span> public <span class="token2">function</span> <span class="token6">disable</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token3">true</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">// 插件升级时的处理(可选)</span> public <span class="token2">function</span> <span class="token6">upgrade</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token3">true</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ```