Example #1
0
 private function init()
 {
     //get user requested route
     if (isset($_GET['node'])) {
         //define route without parameters (helps with showing base URI request)
         $route = $_GET['node'];
         self::$route = $route;
         //break requested route into chunks in array
         $route_chunks = explode("/", $route);
         //define controller
         $controller = $route_chunks[0];
         self::$controller = $controller;
         //define controller directory
         $controller_dir = CONTROLLER_DIR . $controller;
         self::$controller_dir = $controller_dir;
         //define format
         if (!empty($route_chunks[1])) {
             $format = $route_chunks[1];
             self::$format = $format;
         }
         //define parameters - get full url etc and extract all strings after &..
         global $settings;
         $request_uri = $settings['request_uri'];
         //break requested route into chunks in array
         $route_params = explode("&", $request_uri);
         //remove first value from array & return $route_params as just parameters
         $params_shift = array_shift($route_params);
         //update $params array
         foreach ($route_params as $val) {
             $param_chunks = explode("=", $val);
             $params[$param_chunks[0]] = $param_chunks[1];
         }
         self::$params = $params;
     }
 }
Example #2
0
 private function _init()
 {
     $route = $this->_set_route();
     $route = substr($route, -1, 1) == "/" ? substr($route, 0, -1) : $route;
     $route = $route ? explode("/", $route) : null;
     // define the controller directory
     if (isset(self::$config_route['controller_dir_in_route']) && self::$config_route['controller_dir_in_route'] === true) {
         if (is_array($route) && count($route)) {
             self::$controller_dir = array_shift($route);
         } elseif (isset(self::$config_route["default_controller_dir"])) {
             self::$config_route["default_controller_dir"];
         } else {
             trigger_error("ROUTER: DEFAULT CONTROLLER DIR NOT SET");
         }
     }
     // define the controller
     if (is_array($route) && count($route)) {
         self::$controller = array_shift($route);
     } elseif (isset(self::$config_route['default_controller'])) {
         self::$controller = self::$config_route["default_controller"];
     } else {
         trigger_error("ROUTER: DEFAULT CONTROLLER NOT SET");
     }
     // define action
     if (is_array($route) && count($route)) {
         self::$action = array_shift($route);
     } elseif (isset(self::$config_route['default_action'])) {
         self::$action = self::$config_route['default_action'];
     } else {
         trigger_error("ROUTER: DEFAULT ACTION NOT SET");
     }
     // define the parameters
     if ($route) {
         self::$params = $route;
     }
 }