/** * Cargamos el controlador objetivo del router. * @return nothing */ private static function call_controller() { // Si hubo un error, llamamos al controlador correspondiente if (self::$error !== null) { self::$target_routing = self::$error_routes; } // DESPUÉS DE TODO ESTO, CARGAMOS EL CONTROLADOR!!! require_once CONTROLLERS_DIR . 'class.' . strtolower(self::$target_routing['controller']) . EXT; // Hacemos la última validación. $class = '\\Framework\\Controllers\\' . self::$target_routing['controller']; $controller = new $class(); if (get_parent_class($controller) === 'Framework\\Controller') { call_user_func_array(array($controller, self::$target_routing['method']), array()); } else { throw new Core_Exception('El controlador cargado (' . self::$target_routing['controller'] . ') es inválido.', self::$error); } // Esta porción de código sólo es llamada cuando un controlador pide, desde // sí mismo, una redirección, lo cual reiniciará las vistas y el controlador // que había sido cargado previamente if (self::$new_routing['controller'] !== null and self::$new_routing['method'] !== null) { // Removemos el controlador anterior. unset($controller); // Redireccionamos a la nueva ruta. self::$target_routing = self::$new_routing; // anulamos la redirección self::$new_routing = array('controller' => null, 'method' => null, 'value' => null, 'page' => null); // Reiniciamos las vistas. View::clear(); // Reiniciamos los Modelos. Factory::clear(); // Llamamos a esta misma función para continuar el proceso. self::call_controller(self::$new_routing['controller'], self::$new_routing['method']); } }