Skip to content
Snippets Groups Projects
Commit cbbfa355 authored by root's avatar root
Browse files

Initialize simple MVC handler

parent 493d676d
Branches
1 merge request!1Project structure
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [QSA,L]
\ No newline at end of file
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require __DIR__.'/../src/app.php';
$App = DagoJek::Instance();
$App->Start();
\ No newline at end of file
<?php
class DagoJek {
private function __construct() {
// empty constructor
}
public static function Instance() {
static $instance = null;
if ($instance === null) {
$instance = new DagoJek();
}
$instance->includeAllController();
return $instance;
}
private function includeAllController() {
foreach (scandir(dirname(__FILE__)."/controller") as $filename) {
$path = dirname(__FILE__)."/controller" . '/' . $filename;
if (is_file($path)) {
require_once $path;
}
}
}
private function getCurrentUri() {
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
$uri = '/' . trim($uri, '/');
return $uri;
}
public function Start() {
$base_url = $this->getCurrentUri();
switch ($base_url) {
case "/" :
echo "Login page";
break;
case "/login" :
MainController::LoginHandler();
break;
case "/register" :
echo "Register page";
break;
case "/profil" :
echo "Profil page";
break;
default :
echo "404 not found";
}
}
}
?>
\ No newline at end of file
<?php
class MainController {
public static function LoginHandler() {
echo "This is login handler";
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment