🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 13. 插件内置函数 ## 插件内置函数 函数名称说明hook触发事件,前往“5.插件事件”了解addons\_urlurl地址生成get\_addons\_info获取插件信息(info.ini)get\_addons\_info\_all获取所有本地插件信息(info.ini),参数1传入template表示获取所有安装模板信息,addon表示获取所有本地插件信息get\_addons\_config获取插件配置- addons\_url url地址生成 ``` <pre class="calibre16">``` <span class="token5">/** * $url 在插件内只需要写:控制器/操作方法,在其他模块写:插件名称://控制器/操作方法 * $param 参数,附加到URL,用于传参 * @param bool|string $suffix 生成的URL后缀 * @param bool|string $domain 域名 * @return bool|string */</span> <span class="token6">addons_url</span><span class="token1">(</span>$url <span class="token">=</span> <span class="token4">''</span><span class="token1">,</span> $param <span class="token">=</span> <span class="token1">[</span><span class="token1">]</span><span class="token1">,</span> $suffix <span class="token">=</span> <span class="token3">true</span><span class="token1">,</span> $domain <span class="token">=</span> <span class="token3">false</span><span class="token1">)</span> ``` ``` 示例,在插件index控制器生成URL,跳转到test方法 ``` <pre class="calibre16">``` <span class="token"><</span><span class="token">?</span>php namespace addons\demo\controller<span class="token1">;</span> use think\addons\Controller<span class="token1">;</span> class <span class="token6">Index</span> extends <span class="token6">Controller</span> <span class="token1">{</span> public <span class="token2">function</span> <span class="token6">index</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token4">'<a href="'</span><span class="token1">.</span><span class="token6">addons_url</span><span class="token1">(</span><span class="token4">"index/test"</span><span class="token1">)</span><span class="token1">.</span><span class="token4">'">dsfsfsd</a>'</span><span class="token1">;</span> <span class="token1">}</span> public <span class="token2">function</span> <span class="token6">test</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> $config <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token6">getInfo</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token6">dump</span><span class="token1">(</span>$config<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 其他模块生成URL需要写上插件名称,例如前台模板跳转到插件控制器test方法,如下: ``` <pre class="calibre16">``` <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{:addons_url('demo://index/test')}"</span><span class="token">></span>sadasdas<span class="token"><</span><span class="token">/</span>a<span class="token">></span> ``` ``` - get\_addons\_info 获取插件信息 ``` <pre class="calibre16">``` <span class="token5">/** * $name 插件名称 * $type 插件类型, template/addon * $module 所属模块 */</span> <span class="token6">get_addons_info</span><span class="token1">(</span>$name<span class="token1">,</span> $type<span class="token">=</span><span class="token4">'addon'</span><span class="token1">,</span> $module<span class="token">=</span><span class="token4">'index'</span><span class="token1">)</span> ``` ``` 示例,获取test插件信息 ``` <pre class="calibre16">``` public <span class="token2">function</span> <span class="token6">index</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> $info <span class="token">=</span> <span class="token6">get_addons_info</span><span class="token1">(</span><span class="token4">'test'</span><span class="token1">)</span><span class="token1">;</span> <span class="token6">dump</span><span class="token1">(</span>$info<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` - get\_addons\_config 获取插件配置 ``` <pre class="calibre16">``` <span class="token5">/** * $type 类型,可选值:template/addon * $name 插名称标识 * $module 模块 * $complete true-获取所有结构数组,false-获取配置值 */</span> <span class="token6">get_addons_config</span><span class="token1">(</span>$type<span class="token1">,</span> $name<span class="token1">,</span> $module<span class="token">=</span><span class="token4">''</span><span class="token1">,</span> $complete<span class="token">=</span><span class="token3">false</span><span class="token1">)</span> ``` ``` 示例,获取test配置信息 ``` <pre class="calibre16">``` public <span class="token2">function</span> <span class="token6">index</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> $arr <span class="token">=</span> <span class="token6">get_addons_config</span><span class="token1">(</span><span class="token4">'addon'</span><span class="token1">,</span><span class="token4">'test'</span><span class="token1">)</span><span class="token1">;</span> <span class="token6">dump</span><span class="token1">(</span>$arr<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` ## 前台函数 [助手函数库](Han%20Shu%20Ku.html) ## 后台函数 [助手函数库](Han%20Shu%20Ku.html) ## 公共函数 [助手函数库](Han%20Shu%20Ku.html)