## 开始使用
1. 填写好控制器名称
2. 填写好表单元素
3. 点同步字段,会将表单元素自动同步到表字段,如果不想建表,也要点一下同步,不然前端校验通过不了,包含 `id`、`status`、`isdelete`、`create_time`、`update_time` 的数据类型随便填写,模型会根据选项自动生成,不按此处选择的数据类型生成
4. 勾选需要生成的首页菜单
5. 勾选是否创建模型和验证器
6. 点击生成



>[info] 以下代码、日志全部是自动生成,没有做任何修改,包括缩进,严格的缩进非常方便二次编辑和查阅
## 生成文件
### controller/UserInfo.php
```
namespace appadmincontroller;
thinkLoader::import('controller/Controller', thinkConfig::get('traits_path') , EXT);
use appadminController;
class UserInfo extends Controller
{
use appadmintraitscontrollerController;
// 方法黑名单
protected static $blacklist = [];
protected function filter(&$map)
{
if ($this->request->param("name")) {
$map['name'] = ["like", "%" . $this->request->param("name") . "%"];
}
if ($this->request->param("email")) {
$map['email'] = ["like", "%" . $this->request->param("email") . "%"];
}
}
}
```
### view/user_info/index.html
```
{extend name="template/base" /}
{block name="content"}
{include file="form" /}
{tp:menu menu="add,delete,recyclebin" /}
共有数据 :{$count ?? '0'} 条
| 操作 |
|---|
{tp:menu menu='sedit' /} {tp:menu menu='sdelete' /} |
{$page ?? ''}
{/block}
{block name="script"}
{/block}
```
### view/user_info/recyclebin.html
```
{extend name="template/recyclebin" /}
{block name="script"}
{/block}
```
### view/user_info/th.html
```
```
### view/user_info/td.html
```
```
### view/user_info/form.html
```
```
### view/user_info/edit.html
```
{extend name="template/base" /}
{block name="content"}
{/block}
{block name="script"}
{/block}
```
### view/user_info/config.php
```
return array (
'module' => 'admin',
'menu' =>
array (
0 => 'add',
1 => 'delete',
2 => 'recyclebin',
),
'create_config' => true,
'controller' => 'UserInfo',
'title' => '用户信息',
'form' =>
array (
0 =>
array (
'title' => '姓名',
'name' => 'name',
'type' => 'text',
'option' => '',
'default' => '未填写',
'search' => '1',
'search_type' => 'text',
'require' => '1',
'validate' =>
array (
'datatype' => '*',
'nullmsg' => '请填写姓名',
'errormsg' => '',
),
),
1 =>
array (
'title' => '性别',
'name' => 'sex',
'type' => 'radio',
'option' => '1:男#2:女#0:未填写',
'default' => '0',
'sort' => '1',
'search' => '1',
'search_type' => 'select',
'require' => '1',
'validate' =>
array (
'datatype' => '*',
'nullmsg' => '',
'errormsg' => '',
),
),
2 =>
array (
'title' => '年龄',
'name' => 'age',
'type' => 'number',
'option' => '',
'default' => '',
'sort' => '1',
'search_type' => 'text',
'require' => '1',
'validate' =>
array (
'datatype' => 'n',
'nullmsg' => '',
'errormsg' => '年龄必须是数组',
),
),
4 =>
array (
'title' => '生日',
'name' => 'birthday',
'type' => 'date',
'option' => '',
'default' => '',
'search_type' => 'text',
'validate' =>
array (
'datatype' => '/^\d{4}\-\d{1,2}\-\d{1,2}$/',
'nullmsg' => '',
'errormsg' => '生日必须是yy-mm-dddd格式',
),
),
3 =>
array (
'title' => '邮箱',
'name' => 'email',
'type' => 'text',
'option' => '',
'default' => '',
'search' => '1',
'search_type' => 'text',
'require' => '1',
'validate' =>
array (
'datatype' => 'e',
'nullmsg' => '',
'errormsg' => '邮箱格式错误',
),
),
),
'create_table' => '1',
'create_table_force' => '1',
'table_engine' => 'InnoDB',
'table_name' => '',
'field' =>
array (
1 =>
array (
'name' => 'name',
'type' => 'char(18)',
'default' => '',
'not_null' => '1',
'key' => '1',
'comment' => '姓名',
'extra' => '',
),
2 =>
array (
'name' => 'sex',
'type' => 'tinyint(1)',
'default' => '0',
'not_null' => '1',
'key' => '1',
'comment' => '性别',
'extra' => 'unsigned',
),
3 =>
array (
'name' => 'age',
'type' => 'tinyint(3)',
'default' => '0',
'not_null' => '1',
'key' => '1',
'comment' => '年龄',
'extra' => 'unsigned',
),
4 =>
array (
'name' => 'birthday',
'type' => 'date',
'default' => 'NULL',
'not_null' => '1',
'comment' => '生日',
'extra' => '',
),
5 =>
array (
'name' => 'email',
'type' => 'char(32)',
'default' => '',
'not_null' => '1',
'comment' => '邮箱',
'extra' => '',
),
),
'model' => '1',
'auto_timestamp' => '1',
'validate' => '1',
);
```
### validate/UserInfo.php
```
namespace appadminvalidate;
use thinkValidate;
class UserInfo extends Validate
{
protected $rule = [
"name|姓名" => "require",
"sex|性别" => "require",
"age|年龄" => "require",
"birthday|生日" => "",
"email|邮箱" => "require",
];
}
```
### model/UserInfo.php
```
namespace appadminmodel;
use thinkModel;
class UserInfo extends Model
{
// 指定表名,不含前缀
protected $name = 'user_info';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
}
```
## 生成数据表
下面是 Linux 版 Navicat 截图

下面是从 Linux 版 Navicat 中拷贝出的建表语句
```
CREATE TABLE `tp_user_info` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户信息主键',
`name` char(18) NOT NULL DEFAULT '' COMMENT '姓名',
`sex` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '性别',
`age` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '年龄',
`birthday` date NOT NULL COMMENT '生日',
`email` char(32) NOT NULL DEFAULT '' COMMENT '邮箱',
`isdelete` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '删除状态,1-删除 | 0-正常',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `sex` (`sex`),
KEY `age` (`age`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息';
```
## 生成日志
`runtime/log` 目录下的日志原文:
>[info] 在当天的日志中搜索 build_sql 即可搜索到,日志原文中的标记是 BUILD_SQL
```
[ 2016-11-10T20:22:27+08:00 ] 127.0.0.1 127.0.0.1 POST /admin/generate/run.html
[ log ] tpadmin.dev/admin/generate/run.html [运行时间:0.046898s][吞吐率:21.32req/s] [内存消耗:6,291.78kb] [文件加载:63]
[ sql ] BUILD_SQL:
DROP TABLE IF EXISTS `tp_user_info`;
CREATE TABLE `tp_user_info` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户信息主键',
`name` char(18) NOT NULL DEFAULT '' COMMENT '姓名',
`sex` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '性别',
`age` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '年龄',
`birthday` date NOT NULL COMMENT '生日',
`email` char(32) NOT NULL DEFAULT '' COMMENT '邮箱',
`isdelete` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '删除状态,1-删除 | 0-正常',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `sex` (`sex`),
KEY `age` (`age`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '用户信息';
---------------------------------------------------------------
```



