Beispiel #1
0
 public static function dispatch()
 {
     global $_F;
     self::init();
     if (!$_F['controller'] || !$_F['action']) {
         if (F_RUN_MODE == 'sync') {
             return false;
         }
         throw new Exception("访问路径不正确,没有找到 {$_F['uri']}", 404);
     }
     $path_info = explode('/', $_F['uri']);
     if (isset($path_info[1]) && !isset($path_info[2]) && !isset($path_info[3]) && FConfig::get("global.openDiy")) {
         $pager_table = new FTable('page');
         $pager_info = $pager_table->where("url='" . $_F['uri'] . "'")->find();
         if ($pager_info) {
             $_F['controller'] = 'Controller_Front_Public';
             $_F['default'] = $_F['action'];
             $_F['action'] = 'default';
         }
     } else {
         if (!class_exists($_F['controller'])) {
             if (F_RUN_MODE == 'sync') {
                 return false;
             }
             if ($_F['module']) {
                 $c_backup = str_replace(ucfirst($_F['module']) . '_', '', $_F['controller']);
                 if (class_exists($c_backup)) {
                     $_F['controller'] = $c_backup;
                 } else {
                     throw new Exception("找不到控制器:{$_F['controller']}", 404);
                 }
             } else {
                 throw new Exception("找不到控制器:{$_F['controller']}", 404);
             }
         }
     }
     $controller = new $_F['controller']();
     $action = $_F['action'] . 'Action';
     if (method_exists($controller, $action . "")) {
         if (method_exists($controller, 'beforeAction')) {
             // IMPORTANT beforeAction must return true
             if (!$controller->beforeAction()) {
                 return false;
             }
         }
         // 加载函数类
         require_once FLIB_ROOT . "functions/function_core.php";
         $controller->{$action}();
     } else {
         try {
             $fView = new FView();
             $fView->display();
         } catch (Exception $e) {
             throw new Exception("找不到 {$_F['action']}Action ", 404);
         }
     }
     return true;
 }