多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 开始使用 1. 填写好控制器名称 2. 填写好表单元素 3. 点同步字段,会将表单元素自动同步到表字段,如果不想建表,也要点一下同步,不然前端校验通过不了,包含 `id`、`status`、`isdelete`、`create_time`、`update_time` 的数据类型随便填写,模型会根据选项自动生成,不按此处选择的数据类型生成 4. 勾选需要生成的首页菜单 5. 勾选是否创建模型和验证器 6. 点击生成 ![](https://box.kancloud.cn/b958c0ef4d453ce575f52a29b9e38d5a_1851x966.png) ![](https://box.kancloud.cn/ceb7a46fca5304ebb2e8dd3c88669e3d_1842x961.png) ![](https://box.kancloud.cn/7f943e99240e7d86ba656a2ebc43ff91_1836x965.png) ![](https://box.kancloud.cn/5ed815d6a9be67d13412594a3198a20c_1852x966.png) ![](https://box.kancloud.cn/8d273bc1da48f400e7a153a849259cf6_1853x965.png) >[info] 以下代码、日志全部是自动生成,没有做任何修改,包括缩进,严格的缩进非常方便二次编辑和查阅 ## 生成文件 ### controller/one/two/ThreeFour.php ``` <?php namespace app\admin\controller\one\two; \think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT); use app\admin\Controller; class ThreeFour extends Controller { use \app\admin\traits\controller\Controller; // 方法黑名单 protected static $blacklist = []; protected static $isdelete = false; protected function filter(&$map) { if ($this->request->param("text")) { $map['text'] = ["like", "%" . $this->request->param("text") . "%"]; } if ($this->request->param("textarea")) { $map['textarea'] = ["like", "%" . $this->request->param("textarea") . "%"]; } } } ``` ### view/one/two/three_four/index.html ``` {extend name="template/base" /} {block name="content"} <div class="page-container"> <form class="mb-20" method="get" action="{:\\think\\Url::build($Request.action)}"> <input type="text" class="input-text" style="width:250px" placeholder="文本" name="text" value="{$Request.param.text}" > <div class="select-box" style="width:250px"> <select name="select" class="select"> <option value="key1">val1</option> <option value="key2">val2</option> </select> </div> <div class="select-box" style="width:250px"> <select name="radio" class="select"> <option value="">所有单选框</option> {foreach name="$Think.config.conf.sex" item='v' key='k'} <option value="{$k}">{$v}</option> {/foreach} </select> </div> <input type="text" class="input-text" style="width:250px" placeholder="文本域" name="textarea" value="{$Request.param.textarea}" > <input type="text" class="input-text Wdate" style="width:250px" placeholder="日期" name="date" value="{$Request.param.date}" {literal} onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" {/literal} > <button type="submit" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜索</button> </form> <div class="cl pd-5 bg-1 bk-gray"> <span class="l"> {tp:menu menu="add,forbid,resume" /} </span> <span class="r pt-5 pr-5"> 共有数据 :<strong>{$count ?? '0'}</strong> 条 </span> </div> <table class="table table-border table-bordered table-hover table-bg mt-20"> <thead> <tr class="text-c"> <th width="25"><input type="checkbox"></th> <th width="">{:sort_by('文本','text')}</th> <th width="">{:sort_by('下拉框','select')}</th> <th width="">{:sort_by('单选框','radio')}</th> <th width="">复选框</th> <th width="">文本域</th> <th width="">密码</th> <th width="">{:sort_by('日期','date')}</th> <th width="70">操作</th> </tr> </thead> <tbody> {volist name="list" id="vo"} <tr class="text-c"> <td><input type="checkbox" name="id[]" value="{$vo.id}"></td> <td>{$vo.text|high_light=$Request.param.text}</td> <td>{$vo.select}</td> <td>{$vo.radio}</td> <td>{$vo.checkbox}</td> <td>{$vo.textarea|high_light=$Request.param.textarea}</td> <td>{$vo.password}</td> <td>{$vo.date}</td> <td class="f-14"> {$vo.status|show_status=$vo.id} {tp:menu menu='sedit' /} {tp:menu menu='sdeleteforever' /} </td> </tr> {/volist} </tbody> </table> <div class="page-bootstrap">{$page ?? ''}</div> </div> {/block} {block name="script"} <script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script> <script> $(function () { $("[name='select']").find("[value='{$Request.param.select}']").attr("selected", true); $("[name='radio']").find("[value='{$Request.param.radio}']").attr("selected", true); }) </script> {/block} ``` >[info] 因为没有选择创建回收站(recyclebin.html)自动合并 th.html、td.html、form.html 到 index.html 文件中 ### view/one/two/three_four/edit.html ``` {extend name="template/base" /} {block name="content"} <div class="page-container"> <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Request::instance()->baseUrl()}"> <input type="hidden" name="id" value="{:isset($vo.id)?$vo.id:''}"> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>文本:</label> <div class="formControls col-xs-6 col-sm-6"> <input type="text" class="input-text" placeholder="文本" name="text" value="{$vo.text ?? 'default_value'}" > </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3">下拉框:</label> <div class="formControls col-xs-6 col-sm-6"> <div class="select-box"> <select name="select" class="select" datatype="n" nullmsg="请选择下拉框" errormsg="请填写数字" ignore="ignore"> <option value="key1">val1</option> <option value="key2">val2</option> </select> </div> </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3">单选框:</label> <div class="formControls col-xs-6 col-sm-6 skin-minimal"> {foreach name="$Think.config.conf.sex" item='v' key='k'} <div class="radio-box"> <input type="radio" name="radio" id="radio-{$k}" value="{$k}"> <label for="radio-{$k}">{$v}</label> </div> {/foreach} </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3">复选框:</label> <div class="formControls col-xs-6 col-sm-6 skin-minimal"> <div class="radio-box"> <input type="checkbox" name="checkbox[]" id="checkbox-key1" value="key1"> <label for="checkbox-key1">val1</label> </div> <div class="radio-box"> <input type="checkbox" name="checkbox[]" id="checkbox-key2" value="key2"> <label for="checkbox-key2">val2</label> </div> </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3">文本域:</label> <div class="formControls col-xs-6 col-sm-6"> <textarea class="textarea" placeholder="" name="textarea" onKeyUp="textarealength(this, 100)">{$vo.textarea ?? '我是文本域'}</textarea> <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p> </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>密码:</label> <div class="formControls col-xs-6 col-sm-6"> <input type="password" class="input-text" placeholder="密码" name="password" value="{$vo.password ?? ''}" > </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>日期:</label> <div class="formControls col-xs-6 col-sm-6"> <input type="text" class="input-text Wdate" placeholder="日期" name="date" value="{$vo.date ?? '2016-11-11'}" {literal} onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" {/literal} > </div> <div class="col-xs-3 col-sm-3"></div> </div> <div class="row cl"> <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3"> <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button> <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button> </div> </div> </form> </div> {/block} {block name="script"} <script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script> <script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script> <script> $(function () { $("[name='radio'][value='{$vo.radio ?? '0'}']").attr("checked", true); var checks = ''.split(","); if (checks.length > 0){ for (var i in checks){ $("[name='checkbox[]'][value='"+checks[i]+"']").attr("checked", true); } } $("[name='select']").find("[value='{$vo.select ?? 'key1'}']").attr("selected", true); $('.skin-minimal input').iCheck({ checkboxClass: 'icheckbox-blue', radioClass: 'iradio-blue', increaseArea: '20%' }); $("#form").Validform({ tiptype: 2, ajaxPost: true, showAllError: true, callback: function (ret){ ajax_progress(ret); } }); }) </script> {/block} ``` ### view/one/two/three_four/config.php ``` <?php return array ( 'module' => 'admin', 'menu' => array ( 0 => 'add', 1 => 'forbid', 2 => 'resume', ), 'create_config' => true, 'controller' => 'one.two.ThreeFour', 'title' => '四级控制器', 'form' => array ( 0 => array ( 'title' => '文本', 'name' => 'text', 'type' => 'text', 'option' => '', 'default' => 'default_value', 'sort' => '1', 'search' => '1', 'search_type' => 'text', 'require' => '1', 'validate' => array ( 'datatype' => '*', 'nullmsg' => '', 'errormsg' => '', ), ), 1 => array ( 'title' => '下拉框', 'name' => 'select', 'type' => 'select', 'option' => 'key1:val1#key2:val2', 'default' => 'key1', 'sort' => '1', 'search' => '1', 'search_type' => 'select', 'validate' => array ( 'datatype' => 'n', 'nullmsg' => '', 'errormsg' => '请填写数字', ), ), 2 => array ( 'title' => '单选框', 'name' => 'radio', 'type' => 'radio', 'option' => '{sex}', 'default' => '0', 'sort' => '1', 'search' => '1', 'search_type' => 'select', 'validate' => array ( 'datatype' => '', 'nullmsg' => '', 'errormsg' => '', ), ), 3 => array ( 'title' => '复选框', 'name' => 'checkbox', 'type' => 'checkbox', 'option' => 'key1:val1#key2:val2', 'default' => '', 'search_type' => 'text', 'validate' => array ( 'datatype' => '', 'nullmsg' => '', 'errormsg' => '', ), ), 4 => array ( 'title' => '文本域', 'name' => 'textarea', 'type' => 'textarea', 'option' => '', 'default' => '我是文本域', 'search' => '1', 'search_type' => 'text', 'validate' => array ( 'datatype' => '', 'nullmsg' => '', 'errormsg' => '', ), ), 5 => array ( 'title' => '密码', 'name' => 'password', 'type' => 'password', 'option' => '', 'default' => '', 'search_type' => 'text', 'require' => '1', 'validate' => array ( 'datatype' => '/^\\w{6,32}$/', 'nullmsg' => '请填写密码', 'errormsg' => '密码必须为6~32位', ), ), 6 => array ( 'title' => '日期', 'name' => 'date', 'type' => 'date', 'option' => '', 'default' => '2016-11-11', 'sort' => '1', 'search' => '1', 'search_type' => 'date', 'require' => '1', 'validate' => array ( 'datatype' => '/^\\d{4}(\\-\\d{2}){2}$/', 'nullmsg' => '', 'errormsg' => '日期必须是yyyy-mm-dd格式', ), ), ), 'create_table' => '1', 'table_engine' => 'InnoDB', 'table_name' => '', 'field' => array ( 1 => array ( 'name' => 'text', 'type' => 'varchar(255)', 'default' => '', 'not_null' => '1', 'comment' => '文本', 'extra' => '', ), 2 => array ( 'name' => 'select', 'type' => 'tinyint(3)', 'default' => '1', 'not_null' => '1', 'key' => '1', 'comment' => '下拉框', 'extra' => 'unsigned', ), 3 => array ( 'name' => 'radio', 'type' => 'tinyint(1)', 'default' => '0', 'not_null' => '1', 'key' => '1', 'comment' => '单选框', 'extra' => '', ), 4 => array ( 'name' => 'checkbox', 'type' => 'varchar(255)', 'default' => '', 'not_null' => '1', 'comment' => '复选框', 'extra' => '', ), 5 => array ( 'name' => 'textarea', 'type' => 'text', 'default' => 'NULL', 'not_null' => '1', 'comment' => '文本域', 'extra' => '', ), 6 => array ( 'name' => 'password', 'type' => 'char(32)', 'default' => 'NULL', 'comment' => '密码', 'extra' => '', ), 7 => array ( 'name' => 'date', 'type' => 'date', 'default' => 'NULL', 'comment' => '日期', 'extra' => '', ), ), 'model' => '1', ); ``` ### model/one/two/ThreeFour.php ``` <?php namespace app\admin\model\one\two; use think\Model; class ThreeFour extends Model { // 指定表名,不含前缀 protected $name = 'one_two_three_four'; } ``` ## 生成数据表 下面是 Linux 版 Navicat 截图 ![](https://box.kancloud.cn/7b154887a475a9b1f3457e0f338cfa51_582x326.png) 下面是从 Linux 版 Navicat 中拷贝出的建表语句 ``` CREATE TABLE `tp_one_two_three_four` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '四级控制器主键', `text` varchar(255) NOT NULL DEFAULT '' COMMENT '文本', `select` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '下拉框', `radio` tinyint(1) NOT NULL DEFAULT '0' COMMENT '单选框', `checkbox` varchar(255) NOT NULL DEFAULT '' COMMENT '复选框', `textarea` text NOT NULL COMMENT '文本域', `password` char(32) DEFAULT NULL COMMENT '密码', `date` date DEFAULT NULL COMMENT '日期', `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1-正常 | 0-禁用', PRIMARY KEY (`id`), KEY `select` (`select`), KEY `radio` (`radio`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='四级控制器'; ``` ## 生成日志 `runtime/log` 目录下的日志原文: >[info] 在当天的日志中搜索 build_sql 即可搜索到,日志原文中的标记是 BUILD_SQL ``` [ 2016-11-10T20:43:25+08:00 ] 127.0.0.1 127.0.0.1 POST /admin/generate/run.html [ log ] tpadmin.dev/admin/generate/run.html [运行时间:0.037622s][吞吐率:26.58req/s] [内存消耗:6,304.23kb] [文件加载:63] [ sql ] BUILD_SQL: DROP TABLE IF EXISTS `tp_one_two_three_four`; CREATE TABLE `tp_one_two_three_four` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '四级控制器主键', `text` varchar(255) NOT NULL DEFAULT '' COMMENT '文本', `select` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '下拉框', `radio` tinyint(1) NOT NULL DEFAULT '0' COMMENT '单选框', `checkbox` varchar(255) NOT NULL DEFAULT '' COMMENT '复选框', `textarea` text NOT NULL COMMENT '文本域', `password` char(32) COMMENT '密码', `date` date COMMENT '日期', `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1-正常 | 0-禁用', PRIMARY KEY (`id`), KEY `select` (`select`), KEY `radio` (`radio`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '四级控制器'; --------------------------------------------------------------- ```