>[info] 考虑到很多人不会用命令行,这时你可以用浏览器来模拟命令行来生成文件
## 开始使用
1. 访问 http://yourdomain.com/admin/generate/cmd 会自动生成文件
2. 需要配置在后面通过 GET 请求传参,例如 `generate/cmd?config=genereate&file=all`


根目录下的 `generate.php`
```
return [
'module' => 'admin',
'controller' => 'Test',
'title'=> '测试',
'form' => [
[
'title'=> '字段一',
'name' => 'field1',
'type' => 'radio',
'option' => '1:值一#2:值二#3:值三',
'default' => '默认值',
'sort' => false,
'search' => true,
'search_type' => 'select',
'require' => true,
'validate' => [
'datatype' => '*',
'nullmsg' => '为空信息',
'errormsg' => '错误信息',
],
],
[
'title'=> '字段一',
'name' => 'field2',
'type' => 'date',
'option' => '1:值一#2:值二#3:值三',
'default' => '2',
'sort' => true,
'search' => true,
'search_type' => 'text',
'require' => true,
'validate' => [
'datatype' => 'n',
'nullmsg' => '为空信息',
'errormsg' => '错误信息',
],
],
[
'title'=> '状态',
'name' => 'status',
'type' => 'radio',
'option' => '1:启用#0:禁用',
'default' => '0',
'sort' => false,
'search' => false,
'search_type' => 'select',
'require' => true,
'validate' => [
'datatype' => 'n',
'nullmsg' => '为空信息',
'errormsg' => '错误信息',
],
],
],
'create_table'=> true,
'create_table_force' => false,
'table_name' => '',
'table_engine'=> 'InnoDB',
'field'=> [
[
'name' => 'field1',
'type' => 'varchar(25)',
'default' => 123,
'not_null' => true,
'key' => true,
'comment' => '',
'extra' => '', // 扩展属性,例如AUTO_INCREMENT
],
[
'name'=> 'field2',
'type'=> 'varchar(255)',
'default' => 123,
'allow_null' => true,
'key' => true,
'comment' => '',
'extra' => '', // 扩展属性,例如AUTO_INCREMENT
],
],
'menu' => ['add', 'forbid', 'resume', 'delete', 'recyclebin'],
'auto_timestamp' => true,
'model'=> false,
'validate' => false,
];
```
>[info] 以下代码、日志全部是自动生成,没有做任何修改,包括缩进,严格的缩进非常方便二次编辑和查阅
## 生成文件
### controller/Test.php
```
namespace appadmincontroller;
thinkLoader::import('controller/Controller', thinkConfig::get('traits_path') , EXT);
use appadminController;
class Test extends Controller
{
use appadmintraitscontrollerController;
// 方法黑名单
protected static $blacklist = [];
protected function filter(&$map)
{
if ($this->request->param("field2")) {
$map['field2'] = ["like", "%" . $this->request->param("field2") . "%"];
}
}
}
```
### view/test/index.html
```
{extend name="template/base" /}
{block name="content"}
{include file="form" /}
{tp:menu menu="add,forbid,resume,delete,recyclebin" /}
共有数据 :{$count ?? '0'} 条
| 操作 |
|---|
{$vo.status|show_status=$vo.id} {tp:menu menu='sedit' /} {tp:menu menu='sdelete' /} |
{$page ?? ''}
{/block}
{block name="script"}
{/block}
```
### view/test/recyclebin.html
```
{extend name="template/recyclebin" /}
{block name="script"}
{/block}
```
### view/test/th.html
```
```
### view/test/td.html
```
```
### view/test/form.html
```
```
### view/test/edit.html
```
{extend name="template/base" /}
{block name="content"}
{/block}
{block name="script"}
{/block}
```
### view/test/config.php
```
return array (
'module' => 'admin',
'menu' =>
array (
0 => 'add',
1 => 'forbid',
2 => 'resume',
3 => 'delete',
4 => 'recyclebin',
),
'create_config' => true,
'controller' => 'Test',
'title' => '测试',
'form' =>
array (
0 =>
array (
'title' => '字段一',
'name' => 'field1',
'type' => 'radio',
'option' => '1:值一#2:值二#3:值三',
'default' => '默认值',
'sort' => false,
'search' => true,
'search_type' => 'select',
'require' => true,
'validate' =>
array (
'datatype' => '*',
'nullmsg' => '为空信息',
'errormsg' => '错误信息',
),
),
1 =>
array (
'title' => '字段一',
'name' => 'field2',
'type' => 'date',
'option' => '1:值一#2:值二#3:值三',
'default' => '2',
'sort' => true,
'search' => true,
'search_type' => 'text',
'require' => true,
'validate' =>
array (
'datatype' => 'n',
'nullmsg' => '为空信息',
'errormsg' => '错误信息',
),
),
2 =>
array (
'title' => '状态',
'name' => 'status',
'type' => 'radio',
'option' => '1:启用#0:禁用',
'default' => '0',
'sort' => false,
'search' => false,
'search_type' => 'select',
'require' => true,
'validate' =>
array (
'datatype' => 'n',
'nullmsg' => '为空信息',
'errormsg' => '错误信息',
),
),
),
'create_table' => true,
'create_table_force' => false,
'table_name' => '',
'table_engine' => 'InnoDB',
'field' =>
array (
0 =>
array (
'name' => 'field1',
'type' => 'varchar(25)',
'default' => 123,
'not_null' => true,
'key' => true,
'comment' => '',
'extra' => '',
),
1 =>
array (
'name' => 'field2',
'type' => 'varchar(255)',
'default' => 123,
'allow_null' => true,
'key' => true,
'comment' => '',
'extra' => '',
),
),
'auto_timestamp' => true,
'model' => false,
'validate' => false,
);
```
>[info] 因已经存在 `tp_test` 表,选项中 `create_table_force` 的值为 `false`,未生成数据表



