Exemple #1
0
 /**
  * 路由检查
  */
 public static function check()
 {
     //1、判断路由是否为模块路由
     $route = RouteHandle::getModuleRoute();
     foreach ($route as $item) {
         $module = $item['module'];
         $act = $item['act'];
         $op = $item['op'];
         $namespaces = $item['namespace'];
         //获取控制器路径
         $controllerName = ucfirst($act) . 'Controller';
         $controllerFile = $namespaces ? $namespaces . '/' . $controllerName . '.php' : $controllerName . '.php';
         $controllerPath = APP_PATH . '/modules/' . $module . '/controllers/' . $controllerFile;
         $controllerNamespace = $namespaces ? '\\App\\Modules\\' . $module . '\\Controllers\\' . $namespaces . '\\' : '\\App\\Modules\\' . $module . '\\Controllers\\';
         //验证controller控制器文件和类是否存在
         if (file_exists($controllerPath) == TRUE && class_exists($controllerNamespace . $controllerName)) {
             self::runController($controllerName, $op, $controllerNamespace);
         }
     }
     //2、获取控制器和方法
     $routeModule = RouteHandle::getRoute();
     foreach ($routeModule as $item) {
         $act = $item['act'];
         $op = $item['op'];
         $namespaces = $item['namespace'];
         //获取控制器路径
         $controllerName = ucfirst($act) . 'Controller';
         $controllerFile = $namespaces . '/' . $controllerName . '.php';
         $controllerPath = APP_PATH . '/controllers/' . $controllerFile;
         $controllerNamespace = $namespaces ? '\\App\\Controllers\\' . $namespaces . '\\' : '\\App\\Controllers\\';
         //验证controller控制器文件和类是否存在
         if (file_exists($controllerPath) == TRUE && class_exists($controllerNamespace . $controllerName)) {
             self::runController($controllerName, $op, $controllerNamespace);
         }
     }
     //没有找到路由,跳转404错误
     error_404();
 }