改进控制器类不存在的异常处理

This commit is contained in:
thinkphp
2016-06-28 17:42:28 +08:00
parent 802ead16a8
commit ef71b5e81d
3 changed files with 47 additions and 46 deletions

View File

@@ -23,6 +23,7 @@ return [
'method param miss' => '方法参数错误', 'method param miss' => '方法参数错误',
'method not exists' => '方法不存在', 'method not exists' => '方法不存在',
'module not exists' => '模块不存在', 'module not exists' => '模块不存在',
'controller not exists' => '控制器不存在',
'class not exists' => '类不存在', 'class not exists' => '类不存在',
'template not exists' => '模板文件不存在', 'template not exists' => '模板文件不存在',
'illegal controller name' => '非法的控制器名称', 'illegal controller name' => '非法的控制器名称',

View File

@@ -307,7 +307,9 @@ class App
try { try {
$instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']); $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
if (is_null($instance)) {
throw new HttpException(404, 'controller not exists:' . $controller);
}
// 获取当前操作名 // 获取当前操作名
$action = $actionName . $config['action_suffix']; $action = $actionName . $config['action_suffix'];
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) { if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {

View File

@@ -351,8 +351,6 @@ class Loader
return new $class(Request::instance()); return new $class(Request::instance());
} elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) { } elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) {
return new $emptyClass(Request::instance()); return new $emptyClass(Request::instance());
} else {
throw new ClassNotFoundException('class not exists:' . $class, $class);
} }
} }