Ejemplo n.º 1
0
 public function __construct()
 {
     $this->db = new DB();
     $this->errors = new Errors();
     $this->urlParse();
     try {
         if (file_exists(ROOT_DIR . '/core/controllers/' . $this->controller . '/' . $this->action . '.php')) {
             include_once ROOT_DIR . '/core/controllers/' . $this->controller . '/' . $this->action . '.php';
         } else {
             throw new Exception('Страница не существует');
         }
         $controller = new Controller();
         if (!method_exists($controller, 'index')) {
             throw new Exception('Действие не существует');
         }
         $controller->errors = $this->errors->getErrors();
         $controller->warnings = $this->errors->getWarnings();
         $controller->params = $this->params;
         $controller->index();
     } catch (Exception $e) {
         $this->errors->addError($e->getMessage());
         header('HTTP/1.0 404 Not Found');
         try {
             if (file_exists(ROOT_DIR . '/core/controllers/error404/index.php')) {
                 include_once ROOT_DIR . '/core/controllers/error404/index.php';
             } else {
                 throw new Exception('Не найден шаблон вывода ошибок');
             }
             $controller = new ErrorPage();
             $controller->errors = $this->errors->getErrors();
             $controller->warnings = $this->errors->getWarnings();
             $controller->index();
         } catch (Exception $e) {
             $this->errors->addWarning($e->getMessage());
             $this->errors->showErrorPage();
             die;
         }
     }
 }