Example #1
0
 public static function matchRoute($uri)
 {
     $matched = false;
     foreach (self::$_routes as $key => $value) {
         if ($uri == $key) {
             $matched = true;
             self::$_module = $value['module'];
             self::$_controller = $value['controller'];
             self::$_action = $value['action'];
         }
     }
     if ($matched !== true) {
         header('HTTP/1.0 404 Not Found');
         exit("<h1>404 Not Found</h1>The page that you have requested could not be found.");
     }
 }
 /**
  * Match using default route config
  */
 public function matchDefaultRoutes($_original_uri, $_route_map)
 {
     // iterate through default routes
     foreach (self::$_default_routes as $_key => $_value) {
         // compare URI with the default route rule
         if (preg_match($_key, $_original_uri)) {
             // iterate and compare the set values of the default routing rule
             foreach ($_value as $_k => $_v) {
                 switch ($_k) {
                     case 'controller':
                         if ($_v == 'DEFAULT') {
                             self::$_controller = DEFAULT_CONTROLLER;
                         } else {
                             if ($_v == 'CURRENT') {
                                 self::$_controller = $_route_map[0];
                             } else {
                                 self::$_controller = $_v;
                             }
                         }
                         break;
                     case 'action':
                         if ($_v == 'DEFAULT') {
                             self::$_action = DEFAULT_ACTION;
                         } else {
                             if ($_v == 'CURRENT') {
                                 self::$_action = $_route_map[1];
                             } else {
                                 self::$_action = $_v;
                             }
                         }
                         break;
                     case 'id':
                         self::$_id = $_route_map[self::$_default_routes[$_key]['id']];
                         break;
                     default:
                         break;
                 }
             }
             return true;
         }
         // end if
     }
     // end foreach loop
     return false;
 }
Example #3
0
 private static function _init()
 {
     $url = preg_replace("/[#\\?].*\$/", '', $_SERVER['REQUEST_URI']);
     $_paths = explode('/', $url);
     $paths = array();
     foreach ($_paths as $path) {
         if ($path !== '' && $path != '.' && $path != '..') {
             $paths[] = $path;
         }
     }
     if (!empty($paths[0]) && in_array($paths[0], self::$_modules)) {
         self::$_module = array_shift($paths);
     } else {
         self::$_module = null;
     }
     if (count($paths) == 0) {
         $paths[] = 'index';
     }
     if (count($paths) == 1) {
         $paths[] = 'default';
     }
     self::$_controller = !empty($paths[0]) ? array_shift($paths) : 'index';
     self::$_action = !empty($paths[0]) ? array_shift($paths) : 'default';
     if (count($paths) > 0) {
         foreach ($paths as $path) {
             self::$_params[] = rawurldecode($path);
         }
     }
 }