Exemplo n.º 1
0
 public static function init()
 {
     self::setRoutes();
     self::setGetParams();
     $controller = self::$routes[1];
     $action = self::$routes[2];
     if (empty($controller)) {
         $controller = self::$defaultController;
     }
     if (empty($action)) {
         $action = self::$defaultAction;
     }
     $route = trim(strtolower($controller) . '/' . trim(strtolower($action)));
     $controller_name = ucfirst(trim(strtolower($controller))) . "Controller";
     $method_name = trim(strtolower($action));
     $controller = new $controller_name();
     if (method_exists($controller, $method_name) && App::$access->checkAccess($route)) {
         $controller->{$method_name}();
     } else {
         $controller = new SiteController();
         $controller->error404();
     }
 }
Exemplo n.º 2
0
if (isset($_GET)) {
    foreach ($_GET as $k => $v) {
        $parameters[$k] = $v;
    }
}
// Pour accès ultérieur sans "global"
function parameters()
{
    global $parameters;
    return $parameters;
}
// Gestion des la route : paramètre r = controller/action
if (isset(parameters()["r"])) {
    try {
        $route = parameters()["r"];
        if (strpos($route, "/") === FALSE) {
            list($controller, $action) = array($route, "index");
        } else {
            list($controller, $action) = explode("/", $route);
        }
        $controller = ucfirst($controller) . "Controller";
        $c = new $controller();
        $c->{$action}();
    } catch (Exception $e) {
        $c = new SiteController();
        $c->error404();
    }
} else {
    $c = new SiteController();
    $c->index();
}