mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
改进控制器不存在的错误提示
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
|
use think\exception\ClassNotFoundException;
|
||||||
use think\exception\HttpException;
|
use think\exception\HttpException;
|
||||||
use think\exception\HttpResponseException;
|
use think\exception\HttpResponseException;
|
||||||
use think\exception\RouteNotFoundException;
|
use think\exception\RouteNotFoundException;
|
||||||
@@ -383,10 +384,12 @@ class App
|
|||||||
// 监听module_init
|
// 监听module_init
|
||||||
Hook::listen('module_init', $request);
|
Hook::listen('module_init', $request);
|
||||||
|
|
||||||
$instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
|
try {
|
||||||
if (is_null($instance)) {
|
$instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
|
||||||
throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1));
|
} catch (ClassNotFoundException $e) {
|
||||||
|
throw new HttpException(404, 'controller not exists:' . $e->getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前操作名
|
// 获取当前操作名
|
||||||
$action = $actionName . $config['action_suffix'];
|
$action = $actionName . $config['action_suffix'];
|
||||||
|
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ class Loader
|
|||||||
* @param string $layer 控制层名称
|
* @param string $layer 控制层名称
|
||||||
* @param bool $appendSuffix 是否添加类名后缀
|
* @param bool $appendSuffix 是否添加类名后缀
|
||||||
* @param string $empty 空控制器名称
|
* @param string $empty 空控制器名称
|
||||||
* @return Object|false
|
* @return Object
|
||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
public static function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '')
|
public static function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '')
|
||||||
@@ -420,6 +420,8 @@ class Loader
|
|||||||
return App::invokeClass($class);
|
return App::invokeClass($class);
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user