>[info] 考虑到很多人不会用命令行,这时你可以用浏览器来模拟命令行来生成文件
## 开始使用
1. 访问 http://yourdomain.com/admin/generate/cmd 会自动生成文件
2. 需要配置在后面通过 GET 请求传参,例如 `generate/cmd?config=genereate&file=all`
![](https://box.kancloud.cn/5df95ac77a9e9a60b81deffe282a0ac0_454x138.png)
![](https://box.kancloud.cn/1732821ae7539d845343e61c8c519d01_587x152.png)
根目录下的 `generate.php`
```
<?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
```
<?php
namespace app\admin\controller;
\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);
use app\admin\Controller;
class Test extends Controller
{
use \app\admin\traits\controller\Controller;
// 方法黑名单
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"}
<div class="page-container">
{include file="form" /}
<div class="cl pd-5 bg-1 bk-gray">
<span class="l">
{tp:menu menu="add,forbid,resume,delete,recyclebin" /}
</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">
{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:menu menu='sedit' /}
{tp:menu menu='sdelete' /}
</td>
</tr>
{/volist}
</tbody>
</table>
<div class="page-bootstrap">{$page ?? ''}</div>
</div>
{/block}
{block name="script"}
<script>
$(function () {
$("[name='field1']").find("[value='{$Request.param.field1}']").attr("selected", true);
})
</script>
{/block}
```
### view/test/recyclebin.html
```
{extend name="template/recyclebin" /}
{block name="script"}
<script>
$(function () {
$("[name='field1']").find("[value='{$Request.param.field1}']").attr("selected", true);
})
</script>
{/block}
```
### view/test/th.html
```
<th width="25"><input type="checkbox"></th>
<th width="">字段一</th>
<th width="">{:sort_by('字段一','field2')}</th>
<th width="">状态</th>
```
### view/test/td.html
```
<td><input type="checkbox" name="id[]" value="{$vo.id}"></td>
<td>{$vo.field1}</td>
<td>{$vo.field2|high_light=$Request.param.field2}</td>
<td>{$vo.status|get_status}</td>
```
### view/test/form.html
```
<form class="mb-20" method="get" action="{:\\think\\Url::build($Request.action)}">
<div class="select-box" style="width:250px">
<select name="field1" class="select">
<option value="1">值一</option>
<option value="2">值二</option>
<option value="3">值三</option>
</select>
</div>
<input type="text" class="input-text" style="width:250px" placeholder="字段一" name="field2" value="{$Request.param.field2}" >
<button type="submit" class="btn btn-success"><i class="Hui-iconfont"></i> 搜索</button>
</form>
```
### view/test/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 skin-minimal">
<div class="radio-box">
<input type="radio" name="field1" id="field1-1" value="1" datatype="*" nullmsg="为空信息" errormsg="错误信息">
<label for="field1-1">值一</label>
</div>
<div class="radio-box">
<input type="radio" name="field1" id="field1-2" value="2" datatype="*" nullmsg="为空信息" errormsg="错误信息">
<label for="field1-2">值二</label>
</div>
<div class="radio-box">
<input type="radio" name="field1" id="field1-3" value="3" datatype="*" nullmsg="为空信息" errormsg="错误信息">
<label for="field1-3">值三</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"><span class="c-red">*</span>字段一:</label>
<div class="formControls col-xs-6 col-sm-6">
<input type="text" class="input-text Wdate" placeholder="字段一" name="field2" value="{$vo.field2 ?? '2'}" {literal} onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" {/literal} >
</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 skin-minimal">
<div class="radio-box">
<input type="radio" name="status" id="status-1" value="1" datatype="n" nullmsg="为空信息" errormsg="错误信息">
<label for="status-1">启用</label>
</div>
<div class="radio-box">
<input type="radio" name="status" id="status-0" value="0" datatype="n" nullmsg="为空信息" errormsg="错误信息">
<label for="status-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"> 提交 </button>
<button type="button" class="btn btn-default radius ml-20" onClick="layer_close();"> 取消 </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='field1'][value='{$vo.field1 ?? '默认值'}']").attr("checked", true);
$("[name='status'][value='{$vo.status ?? '0'}']").attr("checked", 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/test/config.php
```
<?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`,未生成数据表
- 概要
- 开始使用
- 写在前面
- 目录结构
- 模板主题支持
- 前置方法before支持
- 数据返回
- 异常接管
- Rbac 权限管理
- 开始使用
- 用户管理
- 分组管理
- 节点管理
- 角色管理
- 使用流程
- 其他
- 代码自动生成 v1.2
- 示例一 - 一级控制器
- 示例二 - 多级控制器
- 示例三 - 从数据表生成
- 示例四 - 指定生成的文件
- 示例五 - 命令行模式
- 示例六 - 模拟命令行模式
- 代码自动生成
- 示例一 - 一级控制器
- 示例二 - 多级控制器
- 控制器
- 公共控制器
- traits 多继承 Controller
- 公开不授权控制器
- 其他控制器
- 标签扩展
- 模板
- 网站操作日志
- 节点图
- 行为驱动
- 其他后端方法
- Excel一键导出
- Excel一键导入
- 文件下载
- 邮件发送
- 七牛文件上传
- id加密
- 前端
- ajax请求
- 表单校验
- 丰富弹层
- 异步操作
- 表格溢出
- 随机字符串
- 自动面包屑导航
- 动态加载文件
- 文件上传
- Tab 切换
- 图片预览
- 二维码生成
- 日历组件
- 升级指导
- 更新日志
- FAQ