function run() { $router = new Router(); try { /** @var RouterResult $result */ $result = $router->process($this->config['routes']); $actionName = $result->getActionName(); $controllerName = $result->getControllerName(); $params = $result->getParams(); /** @var Controller $controller */ $controller = new $controllerName(); $controller->setParams($params); if ($controller instanceof \Framework\Config\ConfigAwareInterface) { $controller->setConfig($this->config); } $viewData = $controller->{$actionName}(); if ($controller->getUseTemplate() == true) { $template = $result->getController() . '/' . $result->getAction(); $useLayout = $controller->getUseLayout(); $view = new View(); $view->display($viewData, $template, $useLayout); } } catch (Exception\NotFoundException $e) { header("HTTP/1.0 404 Not Found"); $message = $this->config['environment'] === \Framework\App::DEVELOPMENT_ENVIRONMENT ? 'Page Not Found' : $e->getMessage(); $view = new View(); $view->display(['message' => $message], 'error/error'); } catch (Exception\BaseException $e) { header("HTTP/1.0 500 Internal Server Error"); $message = $this->config['environment'] === \Framework\App::DEVELOPMENT_ENVIRONMENT ? 'Internal Server Error' : $e->getMessage(); $view = new View(); $view->display(['message' => $message], 'error/error'); } }
/** * Creates the new Request object by getting a new URI object, then parsing * the uri with the Route class. * * Usage: * * $request = new Request('foo/bar'); * * @param string the uri string * @param bool whether or not to route the URI * @param string request method * @return void */ public function __construct($uri, $route = true, $method = null) { $this->uri = new \Uri($uri); $this->method = $method; logger(\Fuel::L_INFO, 'Creating a new Request with URI = "' . $uri . '"', __METHOD__); // check if a module was requested if (count($this->uri->segments()) and $module_path = \Module::exists($this->uri->get_segment(0))) { // check if the module has routes if (is_file($module_path .= 'config/routes.php')) { $module = $this->uri->segments[0]; // load and add the module routes $module_routes = \Fuel::load($module_path); $prepped_routes = array(); foreach ($module_routes as $name => $_route) { if ($name === '_root_') { $name = $module; } elseif (strpos($name, $module . '/') !== 0 and $name != $module and $name !== '_404_') { $name = $module . '/' . $name; } $prepped_routes[$name] = $_route; } // update the loaded list of routes \Router::add($prepped_routes, null, true); } } $this->route = \Router::process($this, $route); if (!$this->route) { return; } $this->module = $this->route->module; $this->controller = $this->route->controller; $this->action = $this->route->action; $this->method_params = $this->route->method_params; $this->named_params = $this->route->named_params; if ($this->route->module !== null) { $this->add_path(\Module::exists($this->module)); } }
$router->addRoute("/admin/temporadas/", array('Admin_Seasons')); $router->addRoute("/admin/temporadas/{$rNum}/", array('Admin_Season')); $router->addRoute("/admin/temporadas/{$rNum}/jornadas/", array('Admin_Season_Weeks')); $router->addRoute("/admin/temporadas/{$rNum}/eventos/", array('Admin_Season_Events')); $router->addRoute("/", array('Index')); $router->addRoute("/batch/", array('Batch')); $router->addRoute("/{$rDir}/jornadas/{$rNum}/", array('Season_Index')); $router->addRoute("/{$rDir}/equipos/", array('Teams')); $router->addRoute("/{$rDir}/equipos/{$rDir}/", array('Team_Index')); $router->addRoute("/{$rDir}/clasificacion/", array('Ranking')); $router->addRoute("/{$rDir}/quiniela/", array('BetsRanking')); $router->addRoute("/{$rDir}/calendario/", array('Calendar')); $router->addRoute("/{$rDir}/", array('Season_Index')); $router->addRoute(".*", array('Error_404')); $route = HTMLResponse::getRoute(); $indent = $router->process($route); if ($indent) { $indentClass = $indent[0]; $indentDir = dirname(str_replace("_", "/", $indentClass)); $indentFile = str_replace("//", "", "pages/{$indentDir}/{$indentClass}.php"); $indentParams = array_slice($indent, 1); if (file_exists("pages/{$indentDir}/{$indentDir}.php")) { require_once "pages/{$indentDir}/{$indentDir}.php"; } if (file_exists($indentFile)) { require_once $indentFile; } $r = new ReflectionClass($indentClass); /** * @var $section PublicSection */
/** * Creates the new Request object by getting a new URI object, then parsing * the uri with the Route class. * * Usage: * * $request = new Request('foo/bar'); * * @param string the uri string * @param bool whether or not to route the URI * @return void */ public function __construct($uri, $route = true) { $this->uri = new \Uri($uri); // check if a module was requested if (count($this->uri->segments) and $modpath = \Fuel::module_exists($this->uri->segments[0])) { // check if the module has routes if (file_exists($modpath .= 'config/routes.php')) { // load and add the module routes $modroutes = \Config::load(\Fuel::load($modpath), $this->uri->segments[0] . '_routes'); foreach ($modroutes as $name => $modroute) { switch ($name) { case '_root_': // map the root to the module default controller/method $name = $this->uri->segments[0]; break; case '_404_': // do not touch the 404 route break; default: // prefix the route with the module name if it isn't done yet if (strpos($name, $this->uri->segments[0] . '/') !== 0 and $name != $this->uri->segments[0]) { $name = $this->uri->segments[0] . '/' . $name; } break; } \Config::set('routes.' . $name, $modroute); } // update the loaded list of routes \Router::add(\Config::get('routes')); } } $this->route = \Router::process($this, $route); if (!$this->route) { return; } if ($this->route->module !== null) { $this->module = $this->route->module; \Fuel::add_module($this->module); $this->add_path(\Fuel::module_exists($this->module)); } $this->directory = $this->route->directory; $this->controller = $this->route->controller; $this->action = $this->route->action; $this->method_params = $this->route->method_params; $this->named_params = $this->route->named_params; }
/** * Creates the new Request object by getting a new URI object, then parsing * the uri with the Route class. * * Usage: * * $request = new Request('foo/bar'); * * @param string the uri string * @param bool whether or not to route the URI * @return void */ public function __construct($uri, $route = true) { $this->uri = new \Uri($uri); // check if a module was requested if (count($this->uri->segments) and $modpath = \Fuel::module_exists($this->uri->segments[0])) { // check if the module has custom routes if (file_exists($modpath .= 'config/routes.php')) { // load and add the routes \Config::load(\Fuel::load($modpath), 'routes'); \Router::add(\Config::get('routes')); } } $this->route = \Router::process($this, $route); if ( ! $this->route) { return false; } if ($this->route->module !== null) { $this->module = $this->route->module; \Fuel::add_module($this->module); $this->add_path(\Fuel::module_exists($this->module)); } $this->directory = $this->route->directory; $this->controller = $this->route->controller; $this->action = $this->route->action; $this->method_params = $this->route->method_params; $this->named_params = $this->route->named_params; }