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

示例二 - 多级控制器 - tpAdmin 文档

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

示例二 - 多级控制器 - tpAdmin 文档


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

![](https://box.kancloud.cn/b958c0ef4d453ce575f52a29b9e38d5a_1851x966.png)

![](https://box.kancloud.cn/ceb7a46fca5304ebb2e8dd3c88669e3d_1842x961.png)

![](https://box.kancloud.cn/7f943e99240e7d86ba656a2ebc43ff91_1836x965.png)

![](https://box.kancloud.cn/5ed815d6a9be67d13412594a3198a20c_1852x966.png)

![](https://box.kancloud.cn/8d273bc1da48f400e7a153a849259cf6_1853x965.png)

>[info] 以下代码、日志全部是自动生成,没有做任何修改,包括缩进,严格的缩进非常方便二次编辑和查阅

## 生成文件

### controller/one/two/ThreeFour.php
```
namespace appadmincontrolleronetwo;

thinkLoader::import('controller/Controller', thinkConfig::get('traits_path') , EXT);

use appadminController;

class ThreeFour extends Controller
{
use appadmintraitscontrollerController;
// 方法黑名单
protected static $blacklist = [];

protected static $isdelete = false;

protected function filter(&$map)
{
if ($this->request->param("text")) {
$map['text'] = ["like", "%" . $this->request->param("text") . "%"];
}
if ($this->request->param("textarea")) {
$map['textarea'] = ["like", "%" . $this->request->param("textarea") . "%"];
}
}
}
```

### view/one/two/three_four/index.html
```
{extend name="template/base" /}
{block name="content"}




{tp:menu menu="add,forbid,resume" /}


共有数据 :{$count ?? '0'}

















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











{/volist}

{:sort_by('文本','text')} {:sort_by('下拉框','select')} {:sort_by('单选框','radio')} 复选框 文本域 密码 {:sort_by('日期','date')} 操作
{$vo.text|high_light=$Request.param.text} {$vo.select} {$vo.radio} {$vo.checkbox} {$vo.textarea|high_light=$Request.param.textarea} {$vo.password} {$vo.date}
{$vo.status|show_status=$vo.id}
{tp:menu menu='sedit' /}
{tp:menu menu='sdeleteforever' /}

{$page ?? ''}

{/block}
{block name="script"}


{/block}

```
>[info] 因为没有选择创建回收站(recyclebin.html)自动合并 th.html、td.html、form.html 到 index.html 文件中

### view/one/two/three_four/edit.html
```
{extend name="template/base" /}
{block name="content"}



{/block}
{block name="script"}



{/block}
```

### view/one/two/three_four/config.php
```

return array (
'module' => 'admin',
'menu' =>
array (
0 => 'add',
1 => 'forbid',
2 => 'resume',
),
'create_config' => true,
'controller' => 'one.two.ThreeFour',
'title' => '四级控制器',
'form' =>
array (
0 =>
array (
'title' => '文本',
'name' => 'text',
'type' => 'text',
'option' => '',
'default' => 'default_value',
'sort' => '1',
'search' => '1',
'search_type' => 'text',
'require' => '1',
'validate' =>
array (
'datatype' => '*',
'nullmsg' => '',
'errormsg' => '',
),
),
1 =>
array (
'title' => '下拉框',
'name' => 'select',
'type' => 'select',
'option' => 'key1:val1#key2:val2',
'default' => 'key1',
'sort' => '1',
'search' => '1',
'search_type' => 'select',
'validate' =>
array (
'datatype' => 'n',
'nullmsg' => '',
'errormsg' => '请填写数字',
),
),
2 =>
array (
'title' => '单选框',
'name' => 'radio',
'type' => 'radio',
'option' => '{sex}',
'default' => '0',
'sort' => '1',
'search' => '1',
'search_type' => 'select',
'validate' =>
array (
'datatype' => '',
'nullmsg' => '',
'errormsg' => '',
),
),
3 =>
array (
'title' => '复选框',
'name' => 'checkbox',
'type' => 'checkbox',
'option' => 'key1:val1#key2:val2',
'default' => '',
'search_type' => 'text',
'validate' =>
array (
'datatype' => '',
'nullmsg' => '',
'errormsg' => '',
),
),
4 =>
array (
'title' => '文本域',
'name' => 'textarea',
'type' => 'textarea',
'option' => '',
'default' => '我是文本域',
'search' => '1',
'search_type' => 'text',
'validate' =>
array (
'datatype' => '',
'nullmsg' => '',
'errormsg' => '',
),
),
5 =>
array (
'title' => '密码',
'name' => 'password',
'type' => 'password',
'option' => '',
'default' => '',
'search_type' => 'text',
'require' => '1',
'validate' =>
array (
'datatype' => '/^\w{6,32}$/',
'nullmsg' => '请填写密码',
'errormsg' => '密码必须为6~32位',
),
),
6 =>
array (
'title' => '日期',
'name' => 'date',
'type' => 'date',
'option' => '',
'default' => '2016-11-11',
'sort' => '1',
'search' => '1',
'search_type' => 'date',
'require' => '1',
'validate' =>
array (
'datatype' => '/^\d{4}(\-\d{2}){2}$/',
'nullmsg' => '',
'errormsg' => '日期必须是yyyy-mm-dd格式',
),
),
),
'create_table' => '1',
'table_engine' => 'InnoDB',
'table_name' => '',
'field' =>
array (
1 =>
array (
'name' => 'text',
'type' => 'varchar(255)',
'default' => '',
'not_null' => '1',
'comment' => '文本',
'extra' => '',
),
2 =>
array (
'name' => 'select',
'type' => 'tinyint(3)',
'default' => '1',
'not_null' => '1',
'key' => '1',
'comment' => '下拉框',
'extra' => 'unsigned',
),
3 =>
array (
'name' => 'radio',
'type' => 'tinyint(1)',
'default' => '0',
'not_null' => '1',
'key' => '1',
'comment' => '单选框',
'extra' => '',
),
4 =>
array (
'name' => 'checkbox',
'type' => 'varchar(255)',
'default' => '',
'not_null' => '1',
'comment' => '复选框',
'extra' => '',
),
5 =>
array (
'name' => 'textarea',
'type' => 'text',
'default' => 'NULL',
'not_null' => '1',
'comment' => '文本域',
'extra' => '',
),
6 =>
array (
'name' => 'password',
'type' => 'char(32)',
'default' => 'NULL',
'comment' => '密码',
'extra' => '',
),
7 =>
array (
'name' => 'date',
'type' => 'date',
'default' => 'NULL',
'comment' => '日期',
'extra' => '',
),
),
'model' => '1',
);

```
### model/one/two/ThreeFour.php
```
namespace appadminmodelonetwo;

use thinkModel;

class ThreeFour extends Model
{
// 指定表名,不含前缀
protected $name = 'one_two_three_four';

}

```
## 生成数据表
下面是 Linux 版 Navicat 截图

![](https://box.kancloud.cn/7b154887a475a9b1f3457e0f338cfa51_582x326.png)

下面是从 Linux 版 Navicat 中拷贝出的建表语句
```
CREATE TABLE `tp_one_two_three_four` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '四级控制器主键',
`text` varchar(255) NOT NULL DEFAULT '' COMMENT '文本',
`select` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '下拉框',
`radio` tinyint(1) NOT NULL DEFAULT '0' COMMENT '单选框',
`checkbox` varchar(255) NOT NULL DEFAULT '' COMMENT '复选框',
`textarea` text NOT NULL COMMENT '文本域',
`password` char(32) DEFAULT NULL COMMENT '密码',
`date` date DEFAULT NULL COMMENT '日期',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1-正常 | 0-禁用',
PRIMARY KEY (`id`),
KEY `select` (`select`),
KEY `radio` (`radio`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='四级控制器';

```
## 生成日志
`runtime/log` 目录下的日志原文:
>[info] 在当天的日志中搜索 build_sql 即可搜索到,日志原文中的标记是 BUILD_SQL
```
[ 2016-11-10T20:43:25+08:00 ] 127.0.0.1 127.0.0.1 POST /admin/generate/run.html
[ log ] tpadmin.dev/admin/generate/run.html [运行时间:0.037622s][吞吐率:26.58req/s] [内存消耗:6,304.23kb] [文件加载:63]
[ sql ] BUILD_SQL:
DROP TABLE IF EXISTS `tp_one_two_three_four`;
CREATE TABLE `tp_one_two_three_four` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '四级控制器主键',
`text` varchar(255) NOT NULL DEFAULT '' COMMENT '文本',
`select` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '下拉框',
`radio` tinyint(1) NOT NULL DEFAULT '0' COMMENT '单选框',
`checkbox` varchar(255) NOT NULL DEFAULT '' COMMENT '复选框',
`textarea` text NOT NULL COMMENT '文本域',
`password` char(32) COMMENT '密码',
`date` date COMMENT '日期',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1-正常 | 0-禁用',
PRIMARY KEY (`id`),
KEY `select` (`select`),
KEY `radio` (`radio`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '四级控制器';

---------------------------------------------------------------
```

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

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

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