改进create类的自动生成

This commit is contained in:
thinkphp
2015-03-05 14:59:46 +08:00
parent 762c8a5282
commit 4e9d824993

View File

@@ -45,15 +45,14 @@ class Create {
mkdir(APP_PATH.$module.'/'.$path); mkdir(APP_PATH.$module.'/'.$path);
} }
foreach($file as $val){ foreach($file as $val){
$filename = strtolower($val);
switch($path) { switch($path) {
case 'controller':// 控制器 case 'controller':// 控制器
$filename = strtolower($val).$path;
if(!is_file(APP_PATH.$module.'/'.$path.'/'.$filename.'.php')) { if(!is_file(APP_PATH.$module.'/'.$path.'/'.$filename.'.php')) {
file_put_contents(APP_PATH.$module.'/'.$path.'/'.$filename.'.php',"<?php\nnamespace {$module}\\{$path};\nclass {$filename} {\n}"); file_put_contents(APP_PATH.$module.'/'.$path.'/'.$filename.'.php',"<?php\nnamespace {$module}\\{$path};\nclass {$filename} {\n}");
} }
break; break;
case 'model': // 模型 case 'model': // 模型
$filename = strtolower($val).$path;
if(!is_file(APP_PATH.$module.'/'.$path.'/'.$filename.'.php')) { if(!is_file(APP_PATH.$module.'/'.$path.'/'.$filename.'.php')) {
file_put_contents(APP_PATH.$module.'/'.$path.'/'.$filename.'.php',"<?php\nnamespace {$module}\\{$path};\nclass {$filename} extends \Think\Model{\n}"); file_put_contents(APP_PATH.$module.'/'.$path.'/'.$filename.'.php',"<?php\nnamespace {$module}\\{$path};\nclass {$filename} extends \Think\Model{\n}");
} }
@@ -61,7 +60,6 @@ class Create {
case 'view': // 视图 case 'view': // 视图
break; break;
default: default:
$filename = strtolower($val).$path;
if(!is_file(APP_PATH.$module.'/'.$path.'/'.$filename.'.php')) { if(!is_file(APP_PATH.$module.'/'.$path.'/'.$filename.'.php')) {
file_put_contents(APP_PATH.$module.'/'.$path.'/'.$filename.'.php',"<?php\nnamespace {$module}\\{$path};\nclass {$filename} {\n}"); file_put_contents(APP_PATH.$module.'/'.$path.'/'.$filename.'.php',"<?php\nnamespace {$module}\\{$path};\nclass {$filename} {\n}");
} }
@@ -77,13 +75,13 @@ class Create {
// 创建欢迎页面 // 创建欢迎页面
static public function buildHelloController($module) { static public function buildHelloController($module) {
if(!is_file(APP_PATH.$module.'/controller/index_controller.php')) { if(!is_file(APP_PATH.$module.'/controller/index.php')) {
$content = file_get_contents(THINK_PATH.'tpl/default_index.tpl'); $content = file_get_contents(THINK_PATH.'tpl/default_index.tpl');
$content = str_replace('{$module}',$module,$content); $content = str_replace('{$module}',$module,$content);
if(!is_dir(APP_PATH.$module.'/controller')) { if(!is_dir(APP_PATH.$module.'/controller')) {
mkdir(APP_PATH.$module.'/controller'); mkdir(APP_PATH.$module.'/controller');
} }
file_put_contents(APP_PATH.$module.'/controller/index_controller.php',$content); file_put_contents(APP_PATH.$module.'/controller/index.php',$content);
} }
} }