示例#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;
 }
示例#2
0
 public function display($tpl)
 {
     global $_F;
     $this->tpl_parser->display($tpl);
     if ($_F['debug'] && !$_F['in_ajax']) {
         echo FView::getDebugInfo();
     }
 }
示例#3
0
 public function display($tpl)
 {
     global $_F;
     if (isset($_F['var'])) {
         extract($_F['var']);
     }
     if ($tpl[0] == '/' || $tpl[1] == ':') {
         include $tpl;
         exit;
     } else {
         $tplFile = F_APP_ROOT . 'tpl/' . $tpl;
     }
     if (file_exists($tplFile)) {
         include $tplFile;
     } elseif (file_exists($tplFile . ".tpl.php")) {
         include $tplFile . ".tpl.php";
     } else {
         echo "模版文件不存在!" . $tpl . ".tpl.php";
     }
     if ($_F['debug'] && !$_F['in_ajax']) {
         echo FView::getDebugInfo();
     }
     exit;
 }
示例#4
0
 public function load($tpl)
 {
     global $_F;
     $tpl = $this->getDefaultTpl($tpl);
     $this->set('_F', $_F);
     $view_compress = FConfig::get('global.output_compress');
     $contents = $this->fetch($tpl);
     if ($view_compress) {
         // 会有 http:// 这样的都替换没了
         $contents = preg_replace('#^\\s*/' . '/.*$#im', '', $contents);
         $contents = preg_replace('#<!--.+?-->#si', '', $contents);
         $contents = preg_replace('/^\\s+/im', '', $contents);
         $contents = preg_replace('/>\\s+/im', '>', $contents);
         $contents = preg_replace('/\\s*([{};,])\\s*/im', '\\1', $contents);
         //            $contents = preg_replace('/\s+/im', ' ', $contents);
     }
     if ($_F['debug'] && !$_F['in_ajax']) {
         $contents .= FView::getDebugInfo();
     }
     return $contents;
 }