public function load(Router $router, $basepath)
    {
        $loader = new RouteLoader();
        $loader->registerRouter($router);
        $this->_route = $loader->getRequestedRoute($basepath);

        if (isset($this->_route['method']) && $this->_route['method'] == $_SERVER['REQUEST_METHOD']) {
            $controller = 'App\Controllers\\'.$this->_route['controller'];

            if (!class_exists($controller)) {
                throw new \Exception("Class [{$this->_route['controller']}] does not exist!");
            }

            $class = new $controller($this->_route);
            $method = $this->_route['action'];

            if (isset($this->_route['query'])) {
                $request = new Request();

                if (method_exists($class, $method)) {
                    $class->$method($request->setRequest($this->_route['query'])->getObject());
                } else {
                    throw new \Exception("Method [$method] is not defined in $controller!");
                }
            } else {
                if (method_exists($class, $method)) {
                    $class->$method();
                } else {
                    throw new \Exception("Method [$method] is not defined in $controller!");
                }
            }
        } else {
            $this->loadErrorPage('404');
        }
    }
public function load(Router $router, $basepath)
    {
        $loader = new RouteLoader();
        $loader->registerRouter($router);
        $this->_route = $loader->getRequestedRoute($basepath);

        if (isset($this->_route['method']) && $this->_route['method'] == $_SERVER['REQUEST_METHOD']) {
            $controller = 'App\Controllers\\'.$this->_route['controller'];

            if (!class_exists($controller)) {
                throw new \Exception("Class [{$this->_route['controller']}] does not exist!");
            }

            $class = new $controller($this->_route);
            $method = $this->_route['action'];

            if (isset($this->_route['query'])) {
                $request = new Request();

                if (method_exists($class, $method)) {
                    $class->$method($request->setRequest($this->_route['query'])->getObject());
                } else {
                    throw new \Exception("Method [$method] is not defined in $controller!");
                }
            } else {
                if (method_exists($class, $method)) {
                    $class->$method();
                } else {
                    throw new \Exception("Method [$method] is not defined in $controller!");
                }
            }
        } else {
            $this->loadErrorPage('404');
        }
    }
public function load ( Router $ router , $ basepath ) { $ loader = new RouteLoader ( ) ; $ loader -> registerRouter ( $ router ) ; $ this -> _route = $ loader -> getRequestedRoute ( $ basepath ) ; if ( isset ( $ this -> _route [ 'method' ] ) && $ this -> _route [ 'method' ] == $ _SERVER [ 'REQUEST_METHOD' ] ) { $ controller = 'App\Controllers\\' . $ this -> _route [ 'controller' ] ; if ( ! class_exists ( $ controller ) ) { throw new \ Exception ( "Class [{$this->_route['controller']}] does not exist!" ) ; } $ class = new $ controller ( $ this -> _route ) ; $ method = $ this -> _route [ 'action' ] ; if ( isset ( $ this -> _route [ 'query' ] ) ) { $ request = new Request ( ) ; if ( method_exists ( $ class , $ method ) ) { $ class -> $ method ( $ request -> setRequest ( $ this -> _route [ 'query' ] ) -> getObject ( ) ) ; } else { throw new \ Exception ( "Method [$method] is not defined in $controller!" ) ; } } else { if ( method_exists ( $ class , $ method ) ) { $ class -> $ method ( ) ; } else { throw new \ Exception ( "Method [$method] is not defined in $controller!" ) ; } } } else { $ this -> loadErrorPage ( '404' ) ; } }
Loads the controller with the requested route.

@param \Scara\Routing\Router $router   - The router
@param string                $basepath - Application's base path

@return void
Loads the controller with the requested route .