Example #1
0
$control = array_shift($urlParts);
$action = array_shift($urlParts);
/*********  check authentication and set/unset $_SESSION['id']  ***********/
if (!Application::getCurrentByKey('username') && $action != 'authentication') {
    $control = 'auth';
    $action = 'login';
} else {
    switch (true) {
        case !empty($urlParts):
            Application::setCurrentByKey(['pageid' => array_shift($urlParts)]);
            break;
        case !empty($_POST['id']):
            Application::setCurrentByKey(['pageid' => $_POST['id']]);
            break;
        case empty($control):
            Application::unsetCurrentByKey('pageid');
            break;
        default:
            break;
    }
}
/**************  call Controller's Method   ******************************/
$ctrl = $control ?: 'show';
$ctrlClassName = 'App\\Controllers\\' . ucfirst($ctrl);
$act = $action ?: 'all';
$method = 'action' . ucfirst($act);
try {
    $controller = new $ctrlClassName();
    $controller->{$method}();
} catch (E403Exception $e) {
    Application::catchException($e);