这个插件是为ThinkCMF应用开发,而专门写的一个创建数据表的插件。
所以它并没有前端or后端的视图,只是执行写好的spl代码,创建数据表。
cmf_product_category
cmf_product_category_post
cmf_product_post
cmf_product_tag
cmf_product_tag_post
目前其中内置了以上5个数据表,如有需要,请自己添加修改。
效果图:

目录结构:
create_data_table ├─data │ ├─ config.php │ └─CreateDataTable.sql └─CreateDataTablePlugin.php
CreateDataTablePlugin.php文件
< php
// +----------------------------------------------------------------------
// | Wien Designs [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.wien.ren All rights reserved.
// +----------------------------------------------------------------------
// | Author: Oliver Wien <oliverwien@yeah.net>
// +----------------------------------------------------------------------
namespace plugins\create_data_table;
use cmf\lib\Plugin;
use think\DB;
class CreateDataTablePlugin extends Plugin
{
public $info = [
'name' => 'CreateDataTable',
'title' => '创建数据表',
'description' => 'cmf_product_category,cmf_product_category_post,cmf_product_post,cmf_product_tag,cmf_product_tag_post',
'status' => 1,
'author' => 'Wien Designs',
'version' => '1.1',
'demo_url' => '',
'author_url' => ''
];
//插件是否有后台管理界面
public $hasAdmin = 0;
// 插件安装
public function install()
{
//读取数据库配置内容
$dbConfig = Config('database');
$dbSql = cmf_split_sql(PLUGINS_PATH . 'create_data_table/data/CreateDataTable.sql', $dbConfig['prefix'], $dbConfig['charset']);
//检查合法性
if (empty($dbConfig) || empty($dbSql)) {
$this->error("非法安装!");
}
$db = Db::connect($dbConfig);
foreach ($dbSql as $key => $sql) {
try {
$db->execute($sql);
} catch (\Exception $e) {
return false;
}
}
return true;
}
// 插件卸载
public function uninstall()
{
return true;
}
}
config.php文件
< php /** * 配置文件 */ return [ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '#hostname#', // 数据库名 'database' => '#database#', // 用户名 'username' => '#username#', // 密码 'password' => '#password#', // 端口 'hostport' => '#hostport#', // 数据库编码默认采用utf8 'charset' => '#charset#', // 数据库表前缀 'prefix' => '#prefix#', "authcode" => '#authcode#', //#COOKIE_PREFIX# ];
CreateDataTable.sql文件
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- 表结构 cmf_product_category -- ---------------------------- DROP TABLE IF EXISTS `cmf_product_category`; CREATE TABLE `cmf_product_category` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类ID', `parent_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '分类父ID', `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分类名称', `description` varchar(255) NOT NULL COMMENT '分类表述', `path` varchar(255) NOT NULL DEFAULT '' COMMENT '分类层级关系路径', `seo_title` varchar(100) NOT NULL DEFAULT '' COMMENT 'seo标题', `seo_keywords` varchar(255) NOT NULL DEFAULT '' COMMENT 'seo关键词', `seo_description` varchar(255) NOT NULL DEFAULT '' COMMENT 'seo描述', `list_order` float NOT NULL DEFAULT '10000' COMMENT '排序', `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1:发布,0:不发布', `delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间', `list_tpl` varchar(50) NOT NULL DEFAULT '' COMMENT '列表页模板文件', `detail_tpl` varchar(50) NOT NULL DEFAULT '' COMMENT '详细页模板文件', `more` text COMMENT '扩展属性', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- 表结构 cmf_product_category_post -- ---------------------------- DROP TABLE IF EXISTS `cmf_product_category_post`; CREATE TABLE `cmf_product_category_post` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `post_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '文章id', `category_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '分类id', `list_order` float NOT NULL DEFAULT '10000' COMMENT '排序', `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1:发布;0:不发布', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='product应用 分类文章对应表'; -- ---------------------------- -- 表结构 cmf_product_post -- ---------------------------- DROP TABLE IF EXISTS `cmf_product_post`; CREATE TABLE `cmf_product_post` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `user_id` bigint(20) unsigned NOT NULL COMMENT '作者ID', `post_title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'post标题', `post_keywords` varchar(150) NOT NULL DEFAULT '' COMMENT '关键词', `post_description` varchar(255) NOT NULL DEFAULT '' COMMENT '描述', `post_excerpt` text COMMENT '摘要', `post_content` text COMMENT '文章内容', `post_content_filtered` text COMMENT '处理过的文章内容', `post_source` varchar(150) NOT NULL DEFAULT '' COMMENT '转载文章的来源', `post_hits` bigint(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '查看数', `post_like` bigint(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '点赞数', `comment_count` bigint(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '评论数', `comment_status` tinyint(3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '评论状态;1:允许;0:不允许', `post_status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态;1:已发布;0:未发布;', `is_top` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否置顶;1:置顶;0:不置顶', `recommended` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否推荐;1:推荐;0:不推荐', `create_time` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(10) NOT NULL DEFAULT '0' COMMENT '更新时间', `delete_time` int(10) NOT NULL DEFAULT '0' COMMENT '删除时间', `thumbnail` varchar(100) NOT NULL DEFAULT '' COMMENT '缩略图', `template` varchar(50) NOT NULL DEFAULT '' COMMENT '页面模板', `more` text COMMENT '扩展属性,如缩略图;格式为json', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- 表结构 cmf_product_tag -- ---------------------------- DROP TABLE IF EXISTS `cmf_product_tag`; CREATE TABLE `cmf_product_tag` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类id', `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1:发布,0:不发布', `recommended` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否推荐;1:推荐;0:不推荐', `post_count` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '标签文章数', `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '标签名称', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='product应用 文章标签表'; -- ---------------------------- -- 表结构 cmf_product_tag_post -- ---------------------------- DROP TABLE IF EXISTS `cmf_product_tag_post`; CREATE TABLE `cmf_product_tag_post` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `tag_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '标签 id', `post_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '文章 id', `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1:发布;0:不发布', PRIMARY KEY (`id`), KEY `term_taxonomy_id` (`post_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='product应用 标签文章对应表'; SET FOREIGN_KEY_CHECKS=1;
注意:因为后台调试原因,插件安装、卸载并未作出限制。重复安装插件,会清除当前数据表中内容。
星之书笔记