Example #1
0
 /**
  * Creates the new Request object by getting a new URI object, then parsing
  * the uri with the Route class.
  *
  * @access	public
  * @param	string	the uri string
  * @param	bool	whether or not to route the URI
  * @return	void
  */
 public function __construct($uri, $route)
 {
     $this->uri = new \URI($uri);
     $route = $route === true ? \Route::parse($this->uri) : \Route::parse_match($uri);
     // Attempts to register the first segment as a module
     $mod_path = \Fuel::add_module($route['segments'][0]);
     if ($mod_path !== false) {
         $this->module = array_shift($route['segments']);
         $this->paths = array($mod_path, $mod_path . 'classes' . DS);
     }
     // Check for directory
     $path = (!empty($this->module) ? $mod_path : APPPATH) . 'classes' . DS . 'controller' . DS;
     if (!empty($route['segments']) && is_dir($dirpath = $path . strtolower($route['segments'][0]))) {
         $this->directory = array_shift($route['segments']);
     }
     // When emptied the controller defaults to directory or module
     $controller = empty($this->directory) ? $this->module : $this->directory;
     if (count($route['segments']) == 0) {
         $route['segments'] = array($controller);
     }
     $this->controller = $route['segments'][0];
     $this->action = isset($route['segments'][1]) ? $route['segments'][1] : '';
     $this->method_params = array_slice($route['segments'], 2);
     $this->named_params = $route['named_params'];
     unset($route);
 }