router::run PHP Method

run() public method

public run ( $routes = null )
    function run($routes = null)
    {
        if (is_array($routes)) {
            foreach ($routes as $key => $value) {
                if (is_array($value)) {
                    self::set($value[0], $key, $value[1]);
                } else {
                    self::set($key, $value);
                }
            }
        }
        if ($callback = self::map()) {
            self::call($callback);
        } elseif (self::$not_found !== false) {
            self::call(self::$not_found);
        }
    }

Usage Example

Example #1
0
 public function run()
 {
     safe::safeGPC();
     if (router::run()) {
         return;
     }
     $controller = isset($_GET['c']) ? "{$_GET['c']}Controller" : 'indexController';
     $action = isset($_GET['a']) ? "{$_GET['a']}Action" : 'indexAction';
     if (method_exists($controller, $action)) {
         $controller = new $controller();
         call_user_func(array($controller, $action));
     } else {
         self::error('Action不存在!', "c={$controller} a={$action} 未定义!");
         self::_exit();
     }
 }
All Usage Examples Of router::run