配置文件

DebrisAddon.php

<?php 
namespace addons\Debris;

class DebrisAddon
{
    /**
     * 参数配置 
     * [true,false] 开启|关闭
     * 使用方法在当前文件下的Setting.php
     * @var bool
     */
    public $setting = false;
    
    /**
     * 钩子
     * [true,false] 开启|关闭
     * 使用方法在当前文件下的Setting.php
     * @var bool
     */
    public $hook = true;
    
    /**
     * 类别
     * @var string 
     * [
     *      'plug'      => "功能插件",  
     *      'business'  => "主要业务",
     *      'customer'  => "客户关系",
     *      'activity'  => "营销及活动",
     *      'services'  => "常用服务及工具",
     *      'biz'       => "行业解决方案",
     *      'h5game'    => "H5游戏",
     *      'other'     => "其他",
     * ]
     */
    public $type = 'plug';
    
     /**
     * 微信接收消息类别
     * @var array 
     */
    public $wechatMessage = [];
    
    /**
     * 配置信息
     * @var array
     */
    public $info = [
        'name' => 'Debris',
        'title' => '碎片管理',
        'description' => '碎片管理,网站内有些碎片信息可以进行统一管理如图片、单文章、文字。',
        'author' => '简言',
        'version' => '1.0'
    ];
    
    /**
     * 后台菜单
     * 例如
     *     public $bindings = [
     *          'cover' => [
     *          ],
     *         'menu' => [
     *             [
     *                  'title' => '碎片列表',
     *                  'route' => 'Debris/index',
     *                  'icon' => 'fa fa-weixin',
     *              ]
     *           ...
     *         ],
     *     ];
     * @var array
     */
    public $bindings = [
            'cover' => [
        ],
            'menu' => [
            [
                'title' => '碎片列表',
                'route' => 'debris/index',
                'icon' => ''
            ],
        ]
    ];
    
    /**
     * 保存在当前模块的根目录下面
     * 例如 public $install = 'install.php';
     * 安装SQL,只支持php文件
     * @var string
     */
    public $install = 'install.php';
    
    /**
     * 卸载SQL
     * @var string
     */
    public $uninstall = 'uninstall.php';
    
    /**
     * 更新SQL
     * @var string
     */
    public $upgrade = 'upgrade.php';
}
            

设置文件

Setting.php

<?php
namespace addons\Debris;

use yii;
use common\components\Addons;
use addons\Debris\common\models\Debris;

/**
 * 全局配置
 * Class SettingController
 * @package addons\Debris
 */
class Setting extends Addons
{
    /**
     * @return string
     * 配置默认首页
     */
    public function actionDisplay()
    {
        $request  = Yii::$app->request;
        if($request->isPost)
        {
            $config = "";
            $this->setConfig($config);
        }

        return $this->renderAddon('index',[
            'config' => $this->getConfig()
        ]);
    }

    /**
     * 钩子
     * @param $addon -模块名称
     * @param null $config ->前台传递过来的参数
     * @return string
     */
    public function actionHook($addon,$config = null)
    {
        return $this->rederHook($addon,[
            'model' => Debris::find()->where(['name' => $config])->one()
        ]);
    }
}
            

安装文件

install.php

<?php

$sql = "
DROP TABLE IF EXISTS `yl_addon_sys_debris`;
CREATE TABLE `yl_addon_sys_debris` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) DEFAULT NULL COMMENT '标题',
  `name` varchar(50) DEFAULT NULL COMMENT '标识',
  `type` tinyint(1) DEFAULT '1' COMMENT '类型[1:图片;2:文字:3:链接;文章]',
  `cover` varchar(255) DEFAULT NULL COMMENT '图片',
  `link` varchar(1000) DEFAULT NULL,
  `content` longtext COMMENT '文章',
  `character` varchar(255) DEFAULT NULL COMMENT '文字',
  `append` int(10) DEFAULT '0',
  `updated` int(10) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
";

//执行sql
Yii::$app->getDb()->createCommand($sql)->execute();

卸载文件

uninstall.php

<?php

//表前缀
$table_prefixion = "yl_addon_sys_";
//列表
$table_name = ['debris'];

$sql = "";
foreach ($table_name as $value)
{
    $table = $table_prefixion.$value;
    $sql  .= "DROP TABLE IF EXISTS `{$table}`;";
}

//执行sql
Yii::$app->getDb()->createCommand($sql)->execute();

上次更新:2018-07-12