index() public method

public index ( )
Example #1
0
 function __construct()
 {
     global $url;
     $url = isset($_GET['url']) ? $_GET['url'] : null;
     $url = rtrim($url, '/');
     $url = explode('/', $url);
     $this->db = new Database();
     if (!isset($_SESSION['x_equi']) && $url[0] != 'login') {
         header("location:" . _EQROOT_ . 'login');
     }
     if (empty($url[0])) {
         require 'controllers/dashboard.php';
         $controller = new Dashboard();
         $controller->index();
         return false;
     }
     $file = 'controllers/' . $url[0] . '.php';
     if (file_exists($file)) {
         require $file;
         $controller = new $url[0]();
         $controller->loadModel($url[0]);
         // calling methods
         if (isset($url[2])) {
             if (method_exists($controller, $url[1])) {
                 $controller->{$url[1]}($url[2]);
             } else {
                 $this->error();
             }
         } else {
             if (isset($url[1])) {
                 if (method_exists($controller, $url[1])) {
                     $controller->{$url[1]}();
                 } else {
                     $this->error();
                 }
             } else {
                 $controller->index();
             }
         }
     } else {
         $this->error();
     }
 }
Example #2
0
 function __construct()
 {
     //parent::_construct();
     global $database;
     $vari = $_SERVER['REQUEST_URI'];
     $vari = explode("/", $vari);
     if (isset($_GET['url'])) {
         $url = $_GET['url'];
         $url = rtrim($url);
         $url = explode('/', $_GET['url']);
     } else {
         $url = null;
     }
     if (empty($url[0])) {
         require "controllers/dashboard.php";
         $controller = new Dashboard();
         $controller->index();
         exit;
     }
     $file = "controllers/" . $url[0] . ".php";
     if (file_exists($file)) {
         require $file;
     } elseif ($vari[1] == 'scratch' && count($vari) === 3) {
         require "controllers/pages.php";
         $controller = new Pages();
         $controller->index();
         exit;
     } else {
         require "controllers/error.php";
         $controller = new Error();
         return false;
     }
     $controller = new $url[0]();
     if (isset($url[2]) && !empty($url[2])) {
         $controller->{$url[1]}($url[2]);
     } else {
         if (isset($url[1])) {
             $controller->{$url[1]}();
         }
     }
 }
});
$route->respond('POST', '/store', function ($request, $response) use($home) {
    return $home->store($request, $response);
});
$route->respond('GET', '/login', function () use($home) {
    echo $home->getLogin();
    unset($_SESSION['flash']);
});
$route->respond('POST', '/login', function ($request, $response, $service) use($home) {
    return $home->postLogin($request, $response, $service);
});
$route->respond('GET', '/logout', function ($request, $response, $service) use($home) {
    return $home->logout($request, $response, $service);
});
$route->respond('GET', '/dashboard/index', function ($request, $response) use($dashboard) {
    return $dashboard->index($request, $response);
});
$route->respond('GET', '/dashboard/show', function ($request, $response) use($dashboard) {
    return $dashboard->show($request, $response);
});
$route->respond('GET', '/dashboard/delete/[i:id]', function ($request, $response) use($dashboard) {
    return $dashboard->delete($request, $response);
});
$route->respond('GET', '/dashboard/edit/[i:id]', function ($request, $response) use($dashboard) {
    return $dashboard->edit($request, $response);
});
$route->respond('POST', '/dashboard/edit/[i:id]', function ($request, $response) use($dashboard) {
    return $dashboard->update($request, $response);
});
$route->respond('GET', '/dashboard/leave/index', function ($request, $response) use($leave) {
    return $leave->index($request, $response);