栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > tpAdmin

示例六 - 模拟命令行模式 - tpAdmin 文档

tpAdmin 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

示例六 - 模拟命令行模式 - tpAdmin 文档


>[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`
```

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'}





{include file="th" /}




{volist name="list" id="vo"}

{include file="td" /}


{/volist}

操作

{$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
```

字段一
{:sort_by('字段一','field2')}
状态
```
### view/test/td.html
```

{$vo.field1}
{$vo.field2|high_light=$Request.param.field2}
{$vo.status|get_status}
```
### 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`,未生成数据表

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/214013.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号