Ejemplo n.º 1
0
 function GET()
 {
     $not_found = new NotFoundController();
     $not_found->render();
 }
Ejemplo n.º 2
0
 /**
  * Executes the main application and wrap it into a response for the client.
  */
 private function exec()
 {
     $route = Route::getRoute();
     $admin = $route['admin'] == 1;
     $app = !empty($route['app']) ? $route['app'] : ($admin ? Config::get('config.defaultadminapp') : Config::get('config.defaultapp'));
     // Calculates app's directory and class name
     if ($admin) {
         $app_dir = APPS_DIR . $app . DS . 'admin' . DS;
         $app_name_clear = str_replace(' ', '', ucwords(preg_replace('#[^a-zA-Z]+#', ' ', $app)));
         $app_class = $app_name_clear . 'AdminController';
     } else {
         $app_dir = APPS_DIR . $app . DS;
         $app_name_clear = str_replace(' ', '', ucwords(preg_replace('#[^a-zA-Z]+#', ' ', $app)));
         $app_class = $app_name_clear . 'Controller';
     }
     if (is_dir($app_dir) && file_exists($app_dir . 'controller.php') && !$this->is404) {
         include_once $app_dir . 'controller.php';
         if (class_exists($app_class) && get_parent_class($app_class) == 'Controller') {
             $controller = new $app_class();
             // Instantiate Model if exists
             if (file_exists($app_dir . 'model.php')) {
                 include_once $app_dir . 'model.php';
                 $model_class = str_replace('Controller', 'Model', $app_class);
                 if (class_exists($model_class)) {
                     $controller->setModel(new $model_class());
                 }
             }
             // Instantiate View if exists
             if (file_exists($app_dir . 'view.php')) {
                 include_once $app_dir . 'view.php';
                 $view_class = str_replace('Controller', 'View', $app_class);
                 if (class_exists($view_class) && get_parent_class($view_class) == 'View') {
                     $controller->setView(new $view_class());
                 }
             }
         }
     } else {
         // Set header to a 404 code
         header('HTTP/1.0 404 Not Found');
         // Load the 404 app
         include_once APPS_DIR . '404' . DS . 'controller.php';
         include_once APPS_DIR . '404' . DS . 'view.php';
         $controller = new NotFoundController();
         $view = new NotFoundView();
         $controller->setView($view);
     }
     // Render the app
     $app_rendered = $controller->render();
     // Now render it in the global template
     include_once TEMPLATES_DIR . 'template' . ($admin ? '_admin' : '') . '.php';
 }