改进Loader::controller方法

改进模块找不到的提示信息
This commit is contained in:
thinkphp
2013-04-11 08:27:22 +08:00
parent 0bafaa6919
commit 7da4fa1c9c
2 changed files with 6 additions and 7 deletions

View File

@@ -56,11 +56,7 @@ class App {
// 执行操作
$instance = Loader::controller(CONTROLLER_NAME);
if(!$instance) {
// 是否定义empty控制器
$instance = Loader::controller('empty');
if(!$instance){
E('controller not exists :'.CONTROLLER_NAME,404);
}
E('controller not exists : [ '.MODULE_NAME.'\\Controller\\'.parse_name(CONTROLLER_NAME,1).'Controller ]',404);
}
// 获取当前操作名

View File

@@ -156,7 +156,7 @@ class Loader {
* 实例化(分层)控制器 格式:[模块名/]控制器名
* @param string $name 资源地址
* @param string $layer 控制层名称
* @return Action|false
* @return Object|false
*/
static public function controller($name,$layer='Controller') {
static $_instance = [];
@@ -168,9 +168,12 @@ class Loader {
}
$class = $module.'\\'.$layer.'\\'.parse_name($name,1).$layer;
if(class_exists($class)) {
$action = new $class();
$action = new $class;
$_instance[$name.$layer] = $action;
return $action;
}elseif(class_exists($module.'\\'.$layer.'\\Empty'.$layer)){
$class = $module.'\\'.$layer.'\\Empty'.$layer;
return new $class;
}else{
return false;
}