А как делаете вы?
class Router
{
private static $uri;
public static function notFound() {
header("Status: 404 Not Found");
header('Location:' . $_SERVER['HTTP_HOST'] . 'Error');
}
private static function getController() {
$array['controller'] = 'index';
$array['method'] = 'mainMethod';
self::$uri = explode('/', $_SERVER['REQUEST_URI']);
if (!empty(self::$uri[1])) {
$array['controller'] = self::$uri[1];
}
if ( !empty(self::$uri[2]) ) {
$array['method'] = self::$uri[2];
}
return $array;
}
public static function getRoute() {
$route = self::getController();
$controller = "App_Controllers_".$route['controller'];
$obj = new $controller;
if(method_exists($obj, $route['method'])) {
$obj->$route['method']();
}
else {
self::notFound();
}
}
}