企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
##开始使用 1. 填写好控制器名称 2. 填写好表单元素 3. 点同步字段,会将表单元素自动同步到表字段,如果不想建表,也要点一下同步,不然前端校验通过不了,包含 `id`、`status`、`isdelete`、`create_time`、`update_time` 的数据类型随便填写,模型会根据选项自动生成,不按此处选择的数据类型生成 4. 勾选需要生成的首页菜单 5. 勾选是否创建模型和验证器 6. 点击生成 ![](https://box.kancloud.cn/87826394ba837187a6235353acd9dca7_1460x1076.png) ![](https://box.kancloud.cn/b3d204c1dfe26e923f32750b222a3146_1313x204.png) >[info] 以下代码、日志全部是自动生成,没有做任何修改,包括缩进,严格的缩进非常方便二次编辑和查阅 ##生成文件 ###controller/one/two/three/Forth.php ``` <?php // +---------------------------------------------------------------------- // | tpadmin [a web admin based ThinkPHP5] // +---------------------------------------------------------------------- // | Copyright (c) 2016 tianpian All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: tianpian <tianpian0805@gmail.com> // +---------------------------------------------------------------------- //------------------------ // 四级控制器控制器 //------------------------- namespace app\admin\controller\one\two\three; use app\admin\Controller; class Forth extends Controller { use \app\admin\traits\controller\Controller; protected function filter(&$map) { if ($this->request->param("account")) $map['account'] = ["like", "%" . $this->request->param("account") . "%"]; } } ``` ###view/one/two/three/forth/index.html ``` {extend name="template/base" /} {block name="content"} <div class="page-container"> {include file='form' /} <div class="cl pd-5 bg-1 bk-gray"> <span class="l"> {include file="template/table_menu" menu="add,delete,recycleBin" /} </span> <span class="r pt-5 pr-5"> 共有数据 :<strong>{$count}</strong> 条 </span> </div> <table class="table table-border table-bordered table-hover table-bg mt-20"> <thead> <tr class="text-c"> {include file="th" /} <th width="70">操作</th> </tr> </thead> <tbody> {volist name="list" id="vo"} <tr class="text-c"> {include file="td" /} <td class="f-14"> {$vo.status|show_status=$vo.id} {tp:access action='edit'} <a title="编辑" href="javascript:;" onclick="layer_open('编辑','{:\\think\\Url::build(\'edit\',[\'id\'=>$vo[\'id\']])}')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> {/tp:access} {tp:access action='delete'} <a title="删除" href="javascript:;" onclick="del(this,'{$vo.id}','{:\\think\\Url::build(\'delete\')}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a> {/tp:access} </td> </tr> {/volist} </tbody> </table> <div class="page-bootstrap">{$page}</div> </div> {/block} ``` ###view/one/two/three/forth/th.html ``` <th width="25"><input type="checkbox"></th> <th width="">帐号</th> <th width="">密码</th> <th width="">城市</th> <th width="">{:sort_by('年龄','age')}</th> <th width="">爱好</th> ``` ###view/one/two/three/forth/td.html ``` <td><input type="checkbox" name="id[]" value="{$vo.id}"></td> <td>{$vo.account|high_light=\\think\\Request::instance()->param('account')}</td> <td>{$vo.password}</td> <td>{$vo.city}</td> <td>{$vo.age}</td> <td>{$vo.hobby}</td> ``` ###view/one/two/three/forth/form.html ``` <form class="mb-20" method="get" action="{:\\think\\Url::build(\\think\\Request::instance()->action())}"> <input type="text" class="input-text" style="width:250px" placeholder="帐号" name="account" value="{:\\think\\Request::instance()->param('account')}"> <button type="submit" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜索</button> </form> ``` ###view/one/two/three/forth/recyclebin.html ``` {extend name="template/recyclebin" /} ``` ###view/one/two/three/forth/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" value="{:isset($vo.account)?$vo.account:''}" placeholder="" name="account" datatype="/\w+/" nullmsg="请填写帐号" errormsg="帐号只能是字母数字下划线"> </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" value="{:isset($vo.password)?$vo.password:''}" placeholder="" name="password" datatype="/[^\{\}\(\)]{6,32}/" nullmsg="请填写密码" errormsg="密码只能是不包含括号的6-32位字符"> </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="city" class="select"> <option value="">选项一</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"><span class="c-red">*</span>年龄:</label> <div class="formControls col-xs-6 col-sm-6"> <input type="number" class="input-text" value="{:isset($vo.age)?$vo.age:''}" placeholder="" name="age" datatype="*" nullmsg="请填写年龄"> </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="hobby[]" id="hobby-0" value=""> <label for="hobby-0">选项一</label> </div> </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> $(function () { $("[name='city']").find("[value='{:isset($vo.city)?$vo.city:''}']").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} ``` ###model/one/two/three/Forth.php ``` <?php // +---------------------------------------------------------------------- // | tpadmin [a web admin based ThinkPHP5] // +---------------------------------------------------------------------- // | Copyright (c) 2016 tianpian All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: tianpian <tianpian0805@gmail.com> // +---------------------------------------------------------------------- //------------------------ // 四级控制器模型 //------------------------- namespace app\admin\model\one\two\three; use think\Model; class Forth extends Model { // 指定表名,不含前缀 protected $name = 'one_two_three_forth'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = 'int'; } ``` ###validate/one/two/three/Forth.php ``` <?php // +---------------------------------------------------------------------- // | tpadmin [a web admin based ThinkPHP5] // +---------------------------------------------------------------------- // | Copyright (c) 2016 tianpian All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: tianpian <tianpian0805@gmail.com> // +---------------------------------------------------------------------- //------------------------ // 四级控制器验证器 //------------------------- namespace app\admin\validate\one\two\three; use think\Validate; class Forth extends Validate { protected $rule = [ "account|帐号" => "require", "password|密码" => "require", "age|年龄" => "require", ]; } ``` ##生成数据表 下面是 Linux 版 Navicat 截图 ![](https://box.kancloud.cn/1acf82db408b36576a978685fe706ccd_604x345.png) 下面是从 Linux 版 Navicat 中拷贝出的建表语句 ``` CREATE TABLE `tp_one_two_three_forth` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '四级控制器主键', `account` char(30) DEFAULT NULL COMMENT '帐号', `password` char(32) DEFAULT NULL COMMENT '密码', `city` varchar(255) DEFAULT NULL COMMENT '城市', `age` tinyint(3) DEFAULT NULL COMMENT '年龄', `hobby` varchar(255) DEFAULT NULL COMMENT '爱好', `isdelete` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '删除状态,1-删除 | 0-正常', `create_time` int(11) unsigned NOT NULL COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `account` (`account`), KEY `age` (`age`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='四级控制器'; ``` ##生成日志 runtime/log 目录下的日志原文: >[info] 在当天的日志中搜索 build_sql 即可搜索到,日志原文中的标记是 BUILD_SQL ``` --------------------------------------------------------------- [ 2016-10-26T15:39:02+08:00 ] 127.0.0.1 127.0.0.1 POST /admin/generate/generate.html [ log ] tpadmin.dev/admin/generate/generate.html [运行时间:0.037991s][吞吐率:26.32req/s] [内存消耗:2,767.79kb] [文件加载:58] [ sql ] BUILD_SQL: DROP TABLE IF EXISTS `tp_one_two_three_forth`; CREATE TABLE `tp_one_two_three_forth` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '四级控制器主键', `account` char(30) COMMENT '帐号', `password` char(32) COMMENT '密码', `city` varchar(255) COMMENT '城市', `age` tinyint(3) COMMENT '年龄', `hobby` varchar(255) COMMENT '爱好', `isdelete` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '删除状态,1-删除 | 0-正常', `create_time` int(11) unsigned NOT NULL COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `account` (`account`), KEY `age` (`age`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '四级控制器'; ```