コード例 #1
1
ファイル: Basic.php プロジェクト: sujinw/php-lugit-framework
 public static function exceptionHandle(Exception $exception)
 {
     if (DEBUG_MODE) {
         //直接输出调试信息
         echo nl2br($exception->__toString());
         echo '<hr /><p>Router:</p><pre>';
         print_r(Singleton::getInstance('Router'));
         echo '</pre>';
     } else {
         $code = $exception->getCode();
         $message = nl2br($exception->getMessage());
         /*
                     如果错误码"可能为"合法的http状态码则尝试设置,
                     setStatus()方法会忽略非法的http状态码. */
         if ($code >= 400 && $code <= 505 && !headers_sent()) {
             ResponseModule::setStatus($code);
         }
         $var_list = array('message' => $message, 'code' => $code, 'file' => $exception->getFile(), 'url' => Singleton::getInstance('Router')->getUrl());
         if ($error_file = self::_getErrorFilePath($code)) {
             Lugit::$view = new View($var_list);
             Lugit::$view->render($error_file);
         } else {
             echo 'No error page is found.<pre>';
             print_r($var_list);
             echo '</pre>';
         }
     }
     exit;
 }
コード例 #2
0
ファイル: Router.php プロジェクト: sujinw/php-lugit-framework
 public function dispatch()
 {
     $view_controllerName = $this->controllerName;
     $view_actionName = $this->actionName;
     $controllerClassName = ucfirst($this->controllerName) . 'Controller';
     if (file_exists('./controllers/' . $controllerClassName . '.php')) {
         require './controllers/' . $controllerClassName . '.php';
     } else {
         $view_controllerName = DEFAULT_CONTROLLER_NAME;
         $controllerClassName = DEFAULT_CONTROLLER_NAME . 'Controller';
         Basic::requireOr404('./controllers/' . $controllerClassName . '.php');
     }
     //把controller中输出的内容保留并在view后输出
     ob_start();
     Lugit::$controller = new $controllerClassName($this->array_parameter);
     if (method_exists(Lugit::$controller, $this->actionName . 'Action')) {
         //方法存在,调用方法
         Lugit::$controller->{$this->actionName . 'Action'}();
     } else {
         if (method_exists(Lugit::$controller, DEFAULT_ACTION_NAME . 'Action')) {
             //方法不存在,调用默认方法
             $view_actionName = DEFAULT_ACTION_NAME;
             Lugit::$controller->{DEFAULT_ACTION_NAME . 'Action'}($this->actionName);
         } else {
             //方法不存在 且 默认方法不存在,返回404错误
             throw new NotFoundException();
         }
     }
     $controller_output = ob_get_clean();
     if (empty(Lugit::$view)) {
         Lugit::$view = new View(Lugit::$controller->getVars());
     }
     $template = isset($this->template) ? $this->template : './views/scripts/' . $view_controllerName . '/' . $view_actionName . '.phtml';
     Lugit::$view->render($template);
     echo $controller_output;
 }