一键生成菜单改进:

判断是否有启用软删除(兼容新旧一键生成CRUD)
控制器名驼峰转下划线
pull/98/head
PPPSCN 2019-02-16 19:56:35 +08:00
parent 71617c2526
commit 35b0d64cc2
1 changed files with 14 additions and 1 deletions

View File

@ -197,6 +197,13 @@ class Menu extends Command
if (in_array('trashed', get_class_methods($model))) {
$withSofeDelete = true;
}
} else {
preg_match_all("/\\\$this\->model\s*=\s*new\s+([a-zA-Z\\\]+);/", $classContent, $matches);
\think\Request::instance()->module('admin');
$model = new $matches[1][0];
if (in_array('trashed', get_class_methods($model))) {
$withSofeDelete = true;
}
}
//忽略的类
if (stripos($classComment, "@internal") !== FALSE) {
@ -226,7 +233,13 @@ class Menu extends Command
$pid = 0;
foreach ($controllerArr as $k => $v) {
$key = $k + 1;
$name = strtolower(implode('/', array_slice($controllerArr, 0, $key)));
//驼峰转下划线
$controllerNameArr = array_slice($controllerArr, 0, $key);
foreach ($controllerNameArr as &$val) {
$val = strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $val), "_"));
}
unset($val);
$name = implode('/', $controllerNameArr);
$title = (!isset($controllerArr[$key]) ? $controllerTitle : '');
$icon = (!isset($controllerArr[$key]) ? $controllerIcon : 'fa fa-list');
$remark = (!isset($controllerArr[$key]) ? $controllerRemark : '');