diff --git a/application/admin/Controller.php b/application/admin/Controller.php
index 8eb23b7..a7bd627 100644
--- a/application/admin/Controller.php
+++ b/application/admin/Controller.php
@@ -118,8 +118,11 @@ protected function getModel($controller = '', $type = false)
if (!$controller) {
$controller = $this->request->controller();
}
- if (class_exists($modelName = Loader::parseClass($module, 'model', $controller))) {
- $model = new $modelName();
+ if (
+ class_exists($modelClass = Loader::parseClass($module, 'model', $this->parseCamelCase($controller)))
+ || class_exists($modelClass = Loader::parseClass($module, 'model', $controller))
+ ) {
+ $model = new $modelClass();
$modelType = 'model';
} else {
$model = Db::name($this->parseTable($controller));
@@ -401,4 +404,18 @@ protected function datalist($model, $map, $field = null, $sortBy = '', $asc = fa
}
}
}
+
+ /**
+ * 将abc.def.Gh转为AbcDefGh
+ *
+ * @param $string
+ *
+ * @return mixed
+ */
+ protected function parseCamelCase($string)
+ {
+ return preg_replace_callback('/(\.|^)([a-zA-Z])/', function ($match) {
+ return ucfirst($match[2]);
+ }, $string);
+ }
}
diff --git a/application/admin/controller/one/two/three/Four.php b/application/admin/controller/one/two/three/Four.php
new file mode 100644
index 0000000..fd1a77d
--- /dev/null
+++ b/application/admin/controller/one/two/three/Four.php
@@ -0,0 +1,20 @@
+request->param("field1")) {
+ $map['field1'] = ["like", "%" . $this->request->param("field1") . "%"];
+ }
+ }
+}
diff --git a/application/admin/extra/conf.php b/application/admin/extra/conf.php
index c5db03a..8fe029f 100755
--- a/application/admin/extra/conf.php
+++ b/application/admin/extra/conf.php
@@ -30,4 +30,4 @@
3 => '值三',
4 => '值四',
]
-];
\ No newline at end of file
+];
diff --git a/application/admin/traits/controller/Controller.php b/application/admin/traits/controller/Controller.php
index 96a425e..7f73555 100644
--- a/application/admin/traits/controller/Controller.php
+++ b/application/admin/traits/controller/Controller.php
@@ -76,7 +76,10 @@ public function add()
}
// 写入数据
- if (class_exists($modelClass = Loader::parseClass(Config::get('app.model_path'), 'model', $controller))) {
+ if (
+ class_exists($modelClass = Loader::parseClass(Config::get('app.model_path'), 'model', $this->parseCamelCase($controller)))
+ || class_exists($modelClass = Loader::parseClass(Config::get('app.model_path'), 'model', $controller))
+ ) {
//使用模型写入,可以在模型中定义更高级的操作
$model = new $modelClass();
$ret = $model->isUpdate(false)->save($data);
@@ -127,7 +130,10 @@ public function edit()
}
// 更新数据
- if (class_exists($modelClass = Loader::parseClass(Config::get('app.model_path'), 'model', $controller))) {
+ if (
+ class_exists($modelClass = Loader::parseClass(Config::get('app.model_path'), 'model', $this->parseCamelCase($controller)))
+ || class_exists($modelClass = Loader::parseClass(Config::get('app.model_path'), 'model', $controller))
+ ) {
// 使用模型更新,可以在模型中定义更高级的操作
$model = new $modelClass();
$ret = $model->isUpdate(true)->save($data, ['id' => $data['id']]);
diff --git a/application/admin/view/one/two/three/four/edit.html b/application/admin/view/one/two/three/four/edit.html
new file mode 100644
index 0000000..2b4a87e
--- /dev/null
+++ b/application/admin/view/one/two/three/four/edit.html
@@ -0,0 +1,161 @@
+{extend name="template/base" /}
+{block name="content"}
+
+{/block}
+{block name="script"}
+
+
+
+{/block}
diff --git a/application/admin/view/one/two/three/four/form.html b/application/admin/view/one/two/three/four/form.html
new file mode 100644
index 0000000..6d828ae
--- /dev/null
+++ b/application/admin/view/one/two/three/four/form.html
@@ -0,0 +1,11 @@
+
+
+
+
+ 选项一
+ 选项二
+ 选项三
+
+
+ 搜索
+
\ No newline at end of file
diff --git a/application/admin/view/one/two/three/four/index.html b/application/admin/view/one/two/three/four/index.html
new file mode 100644
index 0000000..2233c9f
--- /dev/null
+++ b/application/admin/view/one/two/three/four/index.html
@@ -0,0 +1,43 @@
+{extend name="template/base" /}
+{block name="content"}
+
+ {include file="form" /}
+
+
+ {tp:menu menu="add,forbid,resume,delete,recyclebin,saveorder" /}
+
+
+ 共有数据 :{$count ?? '0'} 条
+
+
+
+
+
+ {include file="th" /}
+ 操作
+
+
+
+ {volist name="list" id="vo"}
+
+ {include file="td" /}
+
+ {$vo.status|show_status=$vo.id}
+ {tp:menu menu='sedit' /}
+ {tp:menu menu='sdelete' /}
+
+
+ {/volist}
+
+
+
{$page ?? ''}
+
+{/block}
+{block name="script"}
+
+{/block}
+
diff --git a/application/admin/view/one/two/three/four/recyclebin.html b/application/admin/view/one/two/three/four/recyclebin.html
new file mode 100644
index 0000000..8333fa5
--- /dev/null
+++ b/application/admin/view/one/two/three/four/recyclebin.html
@@ -0,0 +1,8 @@
+{extend name="template/recyclebin" /}
+{block name="script"}
+
+{/block}
diff --git a/application/admin/view/one/two/three/four/td.html b/application/admin/view/one/two/three/four/td.html
new file mode 100644
index 0000000..6918dbb
--- /dev/null
+++ b/application/admin/view/one/two/three/four/td.html
@@ -0,0 +1,15 @@
+
+{$vo.field1|high_light=$Request.param.field1}
+{$vo.option}
+{$vo.select}
+{$vo.radio}
+{$vo.checkbox}
+{$vo.password}
+{$vo.textarea}
+{$vo.date}
+{$vo.mobile}
+{$vo.email}
+
+
+{$vo.status|get_status}
\ No newline at end of file
diff --git a/application/admin/view/one/two/three/four/th.html b/application/admin/view/one/two/three/four/th.html
new file mode 100644
index 0000000..3face8b
--- /dev/null
+++ b/application/admin/view/one/two/three/four/th.html
@@ -0,0 +1,13 @@
+
+字段一
+选填
+下拉框
+单选
+复选框
+密码
+文本域
+日期
+手机号
+邮箱
+{:sort_by('排序','sort')}
+状态
\ No newline at end of file
diff --git a/application/common/model/OneTwoThreeFour.php b/application/common/model/OneTwoThreeFour.php
new file mode 100644
index 0000000..d498dec
--- /dev/null
+++ b/application/common/model/OneTwoThreeFour.php
@@ -0,0 +1,12 @@
+ "require",
+ "date|日期" => "require",
+ "mobile|手机号" => "require",
+ "email|邮箱" => "require",
+ "sort|排序" => "require",
+ "status|状态" => "require",
+ ];
+}
diff --git a/extend/Generate.php b/extend/Generate.php
index 84de244..ae45e93 100644
--- a/extend/Generate.php
+++ b/extend/Generate.php
@@ -78,6 +78,21 @@ public function run($data, $option = 'all')
if (!self::checkWritable($pathCheck)) {
throw new Exception("目录没有权限不可写,请执行一下命令修改权限: chmod -R 755 " . realpath($pathCheck), 403);
}
+ if (isset($data['model']) && $data['model']) {
+ $module = $this->readConfig($this->module, 'app', 'model_path', Config::get('app.model_path'));
+ $pathCheck = APP_PATH . $module . DS;
+ if (!self::checkWritable($pathCheck)) {
+ throw new Exception("目录没有权限不可写,请执行一下命令修改权限: chmod -R 755 " . realpath($pathCheck), 403);
+ }
+ }
+ if (isset($data['validate']) && $data['validate']) {
+ $module = $this->readConfig($this->module, 'app', 'validate_path', Config::get('app.validate_path'));
+ $pathCheck = APP_PATH . $module . DS;
+ if (!self::checkWritable($pathCheck)) {
+ throw new Exception("目录没有权限不可写,请执行一下命令修改权限: chmod -R 755 " . realpath($pathCheck), 403);
+ }
+ }
+
// 将菜单全部转为小写
if (isset($data['menu']) && $data['menu']) {
foreach ($data['menu'] as &$menu) {
@@ -122,15 +137,17 @@ public function run($data, $option = 'all')
}
// 创建目录
- $dir_list = ["view" . DS . $this->dir . $this->nameLower];
+ $dir_list = [$this->module . DS . "view" . DS . $this->dir . $this->nameLower];
if (isset($data['model']) && $data['model']) {
- $dir_list[] = "model" . DS . $this->dir;
+ $module = $this->readConfig($this->module, 'app', 'model_path', Config::get('app.model_path'));
+ $dir_list[] = $module . DS . "model";
}
if (isset($data['validate']) && $data['validate']) {
- $dir_list[] = "validate" . DS . $this->dir;
+ $module = $this->readConfig($this->module, 'app', 'validate_path', Config::get('app.validate_path'));
+ $dir_list[] = $module . DS . "validate" . DS . $this->dir;
}
if ($this->dir) {
- $dir_list[] = "controller" . DS . $this->dir;
+ $dir_list[] = $this->module . DS . "controller" . DS . $this->dir;
}
$this->buildDir($dir_list);
@@ -350,11 +367,8 @@ private function delModel($pathView, $phpFile = '')
{
// 获取模型的路径,根据配置文件读取
$module = $this->readConfig($this->module, 'app', 'model_path', Config::get('app.model_path'));
- $file = str_replace(
- ['%MODULE%', '%NAME%'],
- [$module, 'model'],
- $phpFile
- );
+ $name = $this->parseCamelCase($this->dir) . $this->name;
+ $file = APP_PATH . $module . DS . "model" . DS . $name . ".php";
return $this->deleteFile($file);
}
@@ -462,7 +476,7 @@ private function deleteDir($dir)
private function buildDir($dir_list)
{
foreach ($dir_list as $dir) {
- $path = APP_PATH . $this->module . DS . $dir;
+ $path = APP_PATH . $dir;
if (!is_dir($path)) {
// 创建目录
mkdir($path, 0755, true);
@@ -640,11 +654,9 @@ private function buildModel($path, $pathTemplate, $fileName, $tableName, $code,
$template = file_get_contents($pathTemplate . "Model.tpl");
// 获取模型的路径,根据配置文件读取
$module = $this->readConfig($this->module, 'app', 'model_path', Config::get('app.model_path'));
- $file = str_replace(
- ['%MODULE%', '%NAME%'],
- [$module, 'model'],
- $fileName
- );
+ $name = $this->parseCamelCase($this->dir) . $this->name;
+ $file = APP_PATH . $module . DS . "model" . DS . $name . ".php";
+
$autoTimestamp = '';
if (isset($this->data['auto_timestamp']) && $this->data['auto_timestamp']) {
$autoTimestamp = '// 开启自动写入时间戳字段' . "\n"
@@ -653,7 +665,7 @@ private function buildModel($path, $pathTemplate, $fileName, $tableName, $code,
return file_put_contents($file, str_replace(
["[MODULE]", "[TITLE]", "[NAME]", "[NAMESPACE]", "[TABLE]", "[AUTO_TIMESTAMP]"],
- [$module, $this->data['title'], $this->name, $this->namespaceSuffix, $tableName, $autoTimestamp],
+ [$module, $this->data['title'], $name, '', $tableName, $autoTimestamp],
$template
)
);
@@ -1168,4 +1180,18 @@ private function readConfig($module, $scope, $name = null, $default = '')
return $config;
}
}
+
+ /**
+ * 将one/two/three转为OneTwoThree
+ *
+ * @param $name
+ *
+ * @return mixed
+ */
+ private function parseCamelCase($name)
+ {
+ return preg_replace_callback('/((^|\\' . quotemeta(DS) . ')([a-z]))/', function ($matches) {
+ return strtoupper($matches[3]);
+ }, trim($name, DS));
+ }
}
diff --git a/tpadmin.sql b/tpadmin.sql
index e3dcf98..cc5cd98 100644
--- a/tpadmin.sql
+++ b/tpadmin.sql
@@ -4,13 +4,13 @@ Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50716
Source Host : localhost:3306
-Source Database : tpadmin
+Source Database : tpadmin_source
Target Server Type : MYSQL
Target Server Version : 50716
File Encoding : 65001
-Date: 2016-12-10 20:18:41
+Date: 2016-12-17 12:15:26
*/
SET FOREIGN_KEY_CHECKS=0;
@@ -80,7 +80,7 @@ CREATE TABLE `tp_admin_node` (
KEY `isdelete` (`isdelete`),
KEY `sort` (`sort`),
KEY `group_id` (`group_id`)
-) ENGINE=MyISAM AUTO_INCREMENT=60 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+) ENGINE=MyISAM AUTO_INCREMENT=63 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of tp_admin_node
@@ -108,7 +108,7 @@ INSERT INTO `tp_admin_node` VALUES ('20', '1', '2', 'Demo/qrcode', '二维码生
INSERT INTO `tp_admin_node` VALUES ('21', '1', '1', 'NodeMap', '节点图', '', '2', '1', '5', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('22', '1', '1', 'WebLog', '操作日志', '', '2', '1', '6', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('23', '1', '1', 'LoginLog', '登录日志', '', '2', '1', '7', '1', '0');
-INSERT INTO `tp_admin_node` VALUES ('59', '1', '2', 'one.two.three.Forth/index', '多级节点', '', '2', '0', '50', '1', '0');
+INSERT INTO `tp_admin_node` VALUES ('59', '1', '2', 'one.two.three.Four/index', '多级节点', '', '2', '0', '50', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('24', '23', '0', 'index', '首页', '', '3', '0', '50', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('25', '22', '0', 'index', '列表', '', '3', '0', '50', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('26', '22', '0', 'detail', '详情', '', '3', '0', '50', '1', '0');
@@ -141,9 +141,10 @@ INSERT INTO `tp_admin_node` VALUES ('52', '2', '0', 'add', '添加', '', '3', '0
INSERT INTO `tp_admin_node` VALUES ('53', '2', '0', 'edit', '编辑', '', '3', '0', '50', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('54', '2', '0', 'forbid', '默认禁用操作', '', '3', '0', '51', '1', '0');
INSERT INTO `tp_admin_node` VALUES ('55', '2', '0', 'resume', '默认恢复操作', '', '3', '0', '50', '1', '0');
-INSERT INTO `tp_admin_node` VALUES ('56', '1', '2', 'one', '多级菜单演示', '', '2', '1', '13', '1', '0');
-INSERT INTO `tp_admin_node` VALUES ('57', '1', '2', 'two', '三级菜单', '', '1', '1', '0', '1', '0');
-INSERT INTO `tp_admin_node` VALUES ('58', '1', '2', 'three', '四级菜单', '', '2', '0', '4', '1', '0');
+INSERT INTO `tp_admin_node` VALUES ('56', '1', '2', 'one', '一级菜单', '', '2', '1', '13', '1', '0');
+INSERT INTO `tp_admin_node` VALUES ('60', '56', '2', 'two', '二级', '', '3', '1', '50', '1', '0');
+INSERT INTO `tp_admin_node` VALUES ('61', '60', '2', 'three', '三级菜单', '', '4', '1', '50', '1', '0');
+INSERT INTO `tp_admin_node` VALUES ('62', '61', '2', 'Four', '四级菜单', '', '5', '1', '50', '1', '0');
-- ----------------------------
-- Table structure for tp_admin_node_load
@@ -268,7 +269,7 @@ CREATE TABLE `tp_login_log` (
`login_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `uid` (`uid`)
-) ENGINE=InnoDB AUTO_INCREMENT=717 DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tp_login_log
@@ -293,6 +294,36 @@ CREATE TABLE `tp_node_map` (
-- Records of tp_node_map
-- ----------------------------
+-- ----------------------------
+-- Table structure for tp_one_two_three_four
+-- ----------------------------
+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 '四级控制器主键',
+ `field1` varchar(255) DEFAULT NULL COMMENT '字段一',
+ `option` varchar(255) DEFAULT NULL COMMENT '选填',
+ `select` varchar(255) DEFAULT NULL COMMENT '下拉框',
+ `radio` varchar(255) DEFAULT NULL COMMENT '单选',
+ `checkbox` varchar(255) DEFAULT NULL COMMENT '复选框',
+ `password` varchar(255) DEFAULT NULL COMMENT '密码',
+ `textarea` varchar(255) DEFAULT NULL COMMENT '文本域',
+ `date` varchar(255) DEFAULT NULL COMMENT '日期',
+ `mobile` varchar(255) DEFAULT NULL COMMENT '手机号',
+ `email` varchar(255) DEFAULT NULL COMMENT '邮箱',
+ `sort` smallint(5) DEFAULT '50' COMMENT '排序',
+ `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1-正常 | 0-禁用',
+ `isdelete` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '删除状态,1-删除 | 0-正常',
+ `create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
+ `update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
+ PRIMARY KEY (`id`),
+ KEY `sort` (`sort`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='四级控制器';
+
+-- ----------------------------
+-- Records of tp_one_two_three_four
+-- ----------------------------
+INSERT INTO `tp_one_two_three_four` VALUES ('1', 'yuan1994', 'tpadmin', '2', '1', null, '2222', 'https://github.com/yuan1994/tpadmin', '2016-12-07', '13012345678', 'tianpian0805@gmail.com', '50', '1', '0', '1481947278', '1481947353');
+
-- ----------------------------
-- Table structure for tp_web_log_001
-- ----------------------------