/** * Init the controller and execute the action * * @param $route * @return int */ private function renderAction($route) { //loads the class from matched route try { //create a instance of controller $class = $this->loadControllerClass($route['route']['Module'], $route['route']['Controller']); //execute the action ob_start(); $viewClass = $class->{$route['route']['Action'] . 'Action'}(); Application::$action = ob_get_clean(); } catch (\Exception $e) { echo $e->getCode() . ' - ' . $e->getMessage(); Debug::dump($e->getTraceAsString()); exit; } return isset($viewClass) ? $viewClass->getRenderType() : View::HTML; }
public static function loadRoute($route) { // run this method only one time if (!self::$can_run) { return; } self::$can_run = false; $__r_controller = $route['controller']; $__r_action = $route['action']; $__r_params = $route['params']; self::$controller = $__r_controller; $__r_file = Environment::get('Application.controllers') . '/' . $__r_controller . '.php'; if (file_exists($__r_file) == false || is_readable($__r_file) == false) { if (self::$debug) { throw new Exception("Invalid controller file: {$__r_file}"); } else { call_user_func(self::$error404); } } else { include_once $__r_file; $__r_class = $__r_controller . 'Controller'; if (class_exists($__r_class)) { $__r_object = new $__r_class(); if (is_callable(array($__r_object, $__r_action)) == false) { $__r_action = 'index'; } self::$action = $__r_action; call_user_func_array(array($__r_object, $__r_action), $__r_params); } else { throw new Exception("Invalid class: {$__r_class}"); } } }