我是小站长 發表於 2019-6-1 16:52:46

discuz X3.4开发插件导出时的技巧

<font face="Tahoma, &amp;quot;">*************************************************</font><br /><font face="Tahoma, &amp;quot;">** 本教程基于版本:Discuz! X 3.4&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; **</font><br /><font face="Tahoma, &amp;quot;">*************************************************</font><br /><br /><font face="Tahoma, &amp;quot;">在之前的插件体系中,设计一个插件的最后一个步骤就是将插件导出为xml 文件以便安装,如果对于没有单独数据表的插件来说,这样就算是最后一步了,但是如果对于有自己的插件表,甚至还有自己的一个安装流程的插件来说,还需要自行编辑 xml 文件,添加安装脚本的信息,或者是添加卸载等脚本的信息。</font><br /><br /><font face="Tahoma, &amp;quot;">在 Discuz!x</font><font face="Tahoma">3.4</font><font face="Tahoma, &amp;quot;">中只要插件目录中存在 install.php 或者 uninstall.php、 upgrade.php 这些文件,那么在导出的时候都会自动的在 xml 文件中生成对应的数据。极大的方便了插件开发者。</font><br /><br /><font face="Tahoma, &amp;quot;">以官方的“我的马甲”插件为例,在 source\plugin\myrepeats 目录下存在install.php 和 uninstall.php 两个文件,在Discuz!X 3.4中,如果在后台-插件-设计 我的马甲,中点击导出的话是不会有这两个文件的相关信息导出的,在 Discuz!X </font><font face="Tahoma">3.4</font><font face="Tahoma, &amp;quot;"> 中,将会自动在xml 文件中增加:</font><br /><font face="Tahoma, &amp;quot;"><br /></font><br /><ol><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&lt;item id=&quot;installfile&quot;&gt;&lt;!]&gt;&lt;/item&gt;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&lt;item id=&quot;uninstallfile&quot;&gt;&lt;!]&gt;&lt;/item&gt;</ol><br /><font face="Tahoma, &amp;quot;">此代码,即可完全免去手动修改 xml 的操作了~~</font><br /><br /><font face="Tahoma, &amp;quot;">分析代码:</font><br /><font face="Tahoma, &amp;quot;">打开 source\admincp\admincp_plugins.php 这个文件可以看到:</font><font face="Tahoma, &amp;quot;"><br /></font><br /><ol><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(file_exists($plugindir.'/install.php')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $pluginarray['installfile'] = 'install.php';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(file_exists($plugindir.'/uninstall.php')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $pluginarray['uninstallfile'] = 'uninstall.php';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(file_exists($plugindir.'/upgrade.php')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $pluginarray['upgradefile'] = 'upgrade.php';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(file_exists($plugindir.'/check.php')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $pluginarray['checkfile'] = 'check.php';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}</ol><br /><br />Tahoma<em>, </em>插件<em>, </em>quot<em>, </em>文件

tuhemm 發表於 2023-3-29 00:31:45

看一看,支持一下

zhao84 發表於 2023-6-12 22:30:21

学习学习,希望能解决问题。

ehxz 發表於 2023-6-17 06:46:20

https://addon.dismall.com/plugins/tshuz_developer.html

科站网 發表於 2023-6-27 14:50:38

6,学到了

viszoe 發表於 2023-7-1 15:20:31

这个要看

DivivitYan 發表於 2023-8-3 10:58:24

正需要~谢谢

DivivitYan 發表於 2023-8-8 18:49:15

看一看,支持一下
頁: [1]
查看完整版本: discuz X3.4开发插件导出时的技巧