多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
>[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">&#xe665;</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">&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='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`,未生成数据表